我在 Install Shield Limited Edition Visual Studio for Windows 7 中创建了一个安装项目。
在这个项目中,我需要在安装期间作为客户操作运行 C# 应用程序。在此 C# 应用程序中,我需要安装项目运行的路径。
我尝试使用 GetCurrentProcess().MainModule.FileName
或 GetExecutionAssembly()
。位置或 Envirement.CurrentDirectory
。所有这些功能都在应用程序中运行。但是,如果我添加此程序以将项目设置为自定义操作,在安装过程中,我将获得 C:\Windows.
如何获取真实路径?
谢谢
最佳答案
您必须在自定义操作痛苦中将自定义安装程序添加到您的安装项目中。选择安装操作并将 CustomActionData
属性设置为:
/targetdir="[TARGETDIR]\"
然后可以这样访问路径:
[RunInstaller(true)]
public partial class CustomInstaller : System.Configuration.Install.Installer
{
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string path = this.Context.Parameters["targetdir"];
// Do something with path.
}
}
更多https://msdn.microsoft.com/en-us/library/system.configuration.install.installer(v=vs.90).aspx
如果有任何问题请告诉我
关于c# - 从安装项目中获取当前目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37055561/