【问题标题】:Get actual dll path in .Net在.Net中获取实际的dll路径
【发布时间】:2012-11-02 18:16:24
【问题描述】:

我有一个名为 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

【问题讨论】:

  • 错误是什么?你有什么问题?

标签: c# .net wpf dll


【解决方案1】:

你可以使用:

Assembly.GetExecutingAssembly().Location

这将为您提供执行程序集的路径,然后使用:

System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

这将给出包含文件夹。

【讨论】:

【解决方案2】:

你可以试试这个:-

 string path1= System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location;

 string directory= Path.GetDirectoryName( path1 );

【讨论】:

    猜你喜欢
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多