[英]How to get the installation directory in C# after deploying dll's
在dll(C#)中工作时是否有一些聪明的方法来检索安装路径,这将从另一个文件夹中的应用程序调用?
我正在为应用程序开发一个加载项。 我的加载项是用C#编写的。 将使用的应用程序是用C编写的,需要在评估期间编译一些东西,所以我有一个带有C ++ dll的middlestep,用C#处理互操作业务,只显示C可以使用的外部干净的接口。
我部署的是一组.dll和一个.lib和.h用于C ++部分(有时需要静态绑定)。
在尝试设置并从C#dll打印出当前目录信息时:
Console.WriteLine(Directory.GetCurrentDirectory());
要么:
Console.WriteLine(System.Environment.CurrentDirectory);
我得到了可执行文件路径。
那么......再一次,我如何获得我的dll的安装路径?
编辑:他们都工作了! 谢谢你的快速回复!
我想你想要的是Assembly.GetExecutingAssembly().Location
。
这两种方式之一:
using System.IO;
using System.Windows.Forms;
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
要么:
using System.IO;
using System.Reflection;
string path = Path.GetDirectoryName(
Assembly.GetAssembly(typeof(MyClass)).CodeBase);
试试这个:
typeof(TypeInMyModule).Assembly.Location
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.