Get the Assembly path C#

2019-01-25 07:24发布

Im trying to know the path of a dll.... several sites says that ive to use System.Reflection.Assembly.GetExecutingAssembly().Location BUT it returns a path in C:\Windows\Microsoft.Net ... etc... \File.Dll

and i want c:\MyProyect\MiWeb\Bin\File.Dll

any help ?

4条回答
ら.Afraid
2楼-- · 2019-01-25 08:04

The Location of the assembly changes based on redirects and shadow copy. Try using the Codebase property instead.

查看更多
Fickle 薄情
3楼-- · 2019-01-25 08:04

That may actually be the path the program is using... IIRC, It starts out searching for the method call in the GAC before defaulting to the working directory.

查看更多
太酷不给撩
4楼-- · 2019-01-25 08:05

You can do this using:

string file = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
查看更多
贼婆χ
5楼-- · 2019-01-25 08:23

Are you sure you have referenced the right assembly in your project? Sounds like you are using some "default" assembly since it is located in the .NET folder.

查看更多
登录 后发表回答