c# - 在 .Net 中获取实际的 dll 路径

标签 c# .net wpf dll

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

相关文章:

c# - String.Replace 不适用于 php 文件?

c# - EntityFramework where 子句是否始终按相同顺序返回对象

c# - WPF RightClick MouseBinding 发布?

c# - 如何在用户注销或关闭 Windows 时延迟关闭应用程序?

c# - 我应该使用什么数据类型来存储文本数据?

c# - 在 C# 中按字母顺序对数组进行排序

c# - 使用 Linq 读取 XML 文档

c# - 引用类型附加属性 (DependencyProperty) 何时发布?

c# - WPF 控件初始化的顺序 - IsEnabled

c# - 将 Window 项绑定(bind)到 usercontrol 底层控件