Friday, October 23, 2009

How to get the path of the executing assembly

Uri uri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
String assemblyPath = System.IO.Path.GetDirectoryName(uri.LocalPath);

Do not use Assembly.Location property, because if the loaded file was shadow-copied (e.g. it is an application run under NUnit test framework), the location is that of the file after being shadow-copied.

MSDN Library: System.Reflection.Assembly Class

No comments:

Post a Comment