Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows installer 使用Visual Studio安装项目设置InstallPath注册表项_Windows Installer_Registry_Visual Studio Setup Proje - Fatal编程技术网

Windows installer 使用Visual Studio安装项目设置InstallPath注册表项

Windows installer 使用Visual Studio安装项目设置InstallPath注册表项,windows-installer,registry,visual-studio-setup-proje,Windows Installer,Registry,Visual Studio Setup Proje,我正在使用与VisualStudio安装项目一起设计的msi安装程序部署我的应用程序。如何将注册表项设置为应用程序的安装路径 一种方法是在安装程序中创建自定义操作。在自定义操作中,您可以提供CustomActionData“/Path=“[TARGETDIR]*”。在自定义操作代码中,您可以引用上下文参数[“Path”],并在.NET代码中接收安装程序传递的安装路径 既然自定义操作代码中有[TARGETDIR],您就可以继续使用Microsoft.Win32命名空间来设置注册表项 HTH-Wil

我正在使用与VisualStudio安装项目一起设计的msi安装程序部署我的应用程序。如何将注册表项设置为应用程序的安装路径

一种方法是在安装程序中创建自定义操作。在自定义操作中,您可以提供CustomActionData“/Path=“[TARGETDIR]*”。在自定义操作代码中,您可以引用上下文参数[“Path”],并在.NET代码中接收安装程序传递的安装路径

既然自定义操作代码中有[TARGETDIR],您就可以继续使用Microsoft.Win32命名空间来设置注册表项


HTH-Wil

事实上,在我搜索相同的东西时,还提到了以下解决方案:


在注册表项中使用[TARGETDIR]。

仅添加到将[TARGETDIR]作为值放入注册表项中。如果您正在使用vs2012安装屏蔽,请在注册表项中使用[INSTALLDIR]

  • 按照以下步骤操作:
  • 将类库项目添加到安装程序中 解决方案
  • 将安装程序文件添加到类库项目中
  • 将创建的类库项目添加到安装应用程序文件夹
  • 将创建的项目安装程序文件(在“设置自定义操作”窗口中)添加到 “安装”子树项
  • 单击添加的项目并按F4键打开属性窗口
  • 在属性窗口上,将“/pDir=“[TARGETDIR]\”设置为CustomActionData
  • 在安装程序文件(类库项目中)中,编写以下代码将安装路径写入注册表

     Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)
        Dim regsrv As New RegistrationServices
        regsrv.RegisterAssembly(MyBase.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase)
        '--------- adding installation directory to stateSaver ----------
        stateSaver.Add("myTargetDir", Context.Parameters("pDir").ToString)
    End Sub
    
    公共重写子提交(ByVal将数据状态保存为System.Collections.IDictionary) MyBase.Commit(savedState) ''messagebox.show(“salam”) Dim InstallAddress As String=savedState(“myTargetDir”).ToString Dim regKey As RegistryKey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey(“software\pourab\Sanjande”,True) SetValue(“InstalledFolder”,InstallAddress)

  • 我将这个方法与我自己定义的属性一起使用,该属性通过命令行传递到msiexec.exe中,效果非常好。谢谢。这是一个解决问题的好方法,简单明了。老帖子,还是很有用的。不知道为什么这不是答案。SE站点的目标是在未来几年成为知识和答案的资源。对于只有链接的答案,op必须挖掘其他资源,以找到他/她可能不确定的答案。最重要的是,如果你的链接曾经中断,你的答案对于将来访问此页面的任何人来说都是无用的。我给出了我认为是相同的答案。你能回答这个问题吗?这是正确的答案。绝对不需要编写任何代码。 Public Overrides Sub Commit(ByVal savedState As System.Collections.IDictionary) MyBase.Commit(savedState) ''messagebox.show("salam") Dim InstallAddress As String = savedState("myTargetDir").ToString Dim regKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software\pourab\Sanjande", True) regKey.SetValue("InstalledFolder", InstallAddress)