wpf 在 .Net 中获取实际的 dll 路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13200880/
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 actual dll path in .Net
提问by Kishore Kumar
I have a dll named JIMS.Printing.dll which is placed inside the Reporting folder of the main application JIMS.exe.
我有一个名为 JIMS.Printing.dll 的 dll,它位于主应用程序 JIMS.exe 的 Reporting 文件夹中。
But I am getting an error when calling some files inside the Templates folder inside JIMS.Printing.dll code inside of Reporting which running JIMS.exe
但是,在运行 JIMS.exe 的 Reporting 内的 JIMS.Printing.dll 代码中调用 Templates 文件夹内的某些文件时出现错误
JIMS.exe
--------->Reporting
------------------->JIMS.Printing.dll
------------------->Templates
-----------------------------> Files
Code:
代码:
string _templatePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(JIMS.Printing.PrintInvoice)).Location), "Templates");
Code from JIMS.Printing.dll
来自 JIMS.Printing.dll 的代码
JIMS.exe looking for Files inside JIMS.exe Path\Templates\file, But actually the file is in JIMS.Printing.dll Path\Templates\files
JIMS.exe 在 JIMS.exe Path\Templates\file 中寻找 Files,但实际上该文件在 JIMS.Printing.dll Path\Templates\files
回答by catflier
You can use:
您可以使用:
Assembly.GetExecutingAssembly().Location
which will give you the path of the executing assembly then use:
这将为您提供执行程序集的路径,然后使用:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
which will give the containing folder.
这将给出包含文件夹。
回答by Rahul Tripathi
YOu can try this:-
你可以试试这个:-
string path1= System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location;
string directory= Path.GetDirectoryName( path1 );

