获取程序集路径 C#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/917053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the Assembly path C#
提问by jmpena
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
我想知道一个 dll 的路径......几个站点说我使用 System.Reflection.Assembly.GetExecutingAssembly().Location 但它返回 C:\Windows\Microsoft.Net 中的路径......等。 .. \File.Dll
and i want c:\MyProyect\MiWeb\Bin\File.Dll
我想要 c:\MyProyect\MiWeb\Bin\File.Dll
any help ?
有什么帮助吗?
采纳答案by Reed Copsey
You can do this using:
您可以使用以下方法执行此操作:
string file = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
回答by Paul Alexander
The Location of the assembly changes based on redirects and shadow copy. Try using the Codebase property instead.
程序集的位置根据重定向和卷影副本而变化。尝试改用 Codebase 属性。
回答by Ian Jacobs
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.
那实际上可能是程序正在使用的路径... IIRC,它在默认到工作目录之前开始在 GAC 中搜索方法调用。
回答by erikric
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.
您确定在项目中引用了正确的程序集吗?听起来您正在使用一些“默认”程序集,因为它位于 .NET 文件夹中。