gpt4 book ai didi

c# - 安装程序自定义操作 - 注册 COM dll - C#

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:26 25 4
gpt4 key购买 nike

我已经创建了一个 COM 可见项目,并向该项目添加了一个安装向导。我还添加了一个自定义操作类并尝试写入注册表。

下面是一个 wxs 安装程序的示例条目(我没有这方面的经验),我如何在我的自定义操作类的安装操作期间在 C# 中重新创建它?

         <RegistryKey Root='HKCU' Key='Software\Autodesk\Structural\RSA\AddIns\{24D63E1C-E503-4EB4-9381-BF9F6A35E199}'>
<RegistryValue Type='binary' Name='AddInsType' Value='0'/>
<RegistryValue Type='binary' Name='Enable' Value='1'/>
<RegistryValue Type='string' Name='File' Value='[INSTALLDIR]myaddin.dll'/>
<RegistryValue Type='string' Name='Guid' Value='{24D63E1C-E503-4EB4-9381-BF9F6A35E199}'/>
<RegistryValue Type='binary' Name='Guid Type' Value='2'/>
<RegistryValue Type='binary' Name='KeepMenuGrade' Value='0'/>
<RegistryValue Type='string' Name='KeyName' Value='{24D63E1C-E503-4EB4-9381-BF9F6A35E199}'/>

这是我到目前为止在我的自定义操作类中使用的 this answer .将 key_value_name 添加为与我的 COM dll 相同的 GUID 是否正确?

namespace RegisterRoboPython
{
[RunInstaller(true)]
public partial class RegisterRoboPython : Installer
{
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);

const string key_path = "Software\\Autodesk\\Structural\\RSA\\AddIns";
const string key_value_name = "{5a0d8941-241c-481c-9811-2c76a91bf17c}";

RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);

if (key == null)
{
key = Registry.LocalMachine.CreateSubKey(key_path);
}

string tgt_dir = Context.Parameters["TARGETDIR"];

key.SetValue(key_value_name, tgt_dir);

}


public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
}

public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);

const string key_path = "Software\\Autodesk\\Structural\\RSA\\AddIns";
const string key_name = "{5a0d8941-241c-481c-9811-2c76a91bf17c}";

RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path);

if (key.OpenSubKey(key_name) != null)
{
key.DeleteSubKey(key_name);
}

}

public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}

public RegisterRoboPython()
{
InitializeComponent();
}
}

编辑 1:运行安装 .msi 时,我收到以下错误:

system.argumentexception FILE = DOES NOT EXIST 
IF THIS PARAMETER IS USED AS AN INSTALLER OPTION THE FORMAT MUST BE /KEY=[VALUE]

我对此感到困惑,因为我已将 /TARGETDIR = "[TARGETDIR]" 添加到安装/提交 CustomActionData 属性。

所以我的问题是,使用自定义操作注册 COM dll 的正确方法是什么?

我走在正确的轨道上吗?谢谢阅读,汤姆

最佳答案

避免自定义操作:请尽可能避免自定义操作。 Here is my propaganda against them .您只需要知道它们很容易出错。如果有可以执行相同操作的内置功能,请改用它们。


Registry View: Following from this description from Microsoft, please try to use this built-in feature:

  1. Open your Visual Studio Project
  2. On the View menu, point to Editor, and then click Registry.
  3. Create keys and values as appropriate in the registry view

请考虑坚持使用 some other tool for deployment .至少阅读下面对 Visual Studio 安装项目的限制的描述。


Visual Studio 安装程序项目问题:您应该了解 Visual Studio 安装程序项目的一些问题。 推荐您继续使用WiX:


更多链接:

关于c# - 安装程序自定义操作 - 注册 COM dll - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53673151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com