我有一个名为 JIMS.Printing.dll 的 dll,它位于主应用程序 JIMS.exe 的 Reporting 文件夹中。
但是在运行 JIMS.exe 的 Reporting 中的 JIMS.Printing.dll 代码中调用 Templates 文件夹中的某些文件时出现错误
JIMS.exe
--------->Reporting
------------------->JIMS.Printing.dll
------------------->Templates
-----------------------------> Files
代码:
string _templatePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(JIMS.Printing.PrintInvoice)).Location), "Templates");
来自 JIMS.Printing.dll 的代码
JIMS.exe 在 JIMS.exe Path\Templates\file 中寻找文件, 但实际上文件在 JIMS.Printing.dll Path\Templates\files
最佳答案
您可以使用:
Assembly.GetExecutingAssembly().Location
这将为您提供执行程序集的路径,然后使用:
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
这将给出包含的文件夹。
关于c# - 在 .Net 中获取实际的 dll 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13200880/