.net 卸载时,使用Installer类实现的自定义操作不起作用

.net 卸载时,使用Installer类实现的自定义操作不起作用,.net,visual-studio,installation,.net,Visual Studio,Installation,我通过System.Configuration.Install.installerclass实现了WPF应用程序的安装程序。我想在卸载应用程序时删除应用程序添加的registryKey,因此我在CustomAction.dll中编写了以下内容: 使用系统; 命名空间自定义操作 { [System.ComponentModel.RunInstaller(true)] 公共类操作设置:System.Configuration.Install.Installer { 公共覆盖无效卸载(System.C

我通过
System.Configuration.Install.installer
class实现了WPF应用程序的安装程序。我想在卸载应用程序时删除应用程序添加的registryKey,因此我在CustomAction.dll中编写了以下内容:

使用系统;
命名空间自定义操作
{
[System.ComponentModel.RunInstaller(true)]
公共类操作设置:System.Configuration.Install.Installer
{
公共覆盖无效卸载(System.Collections.IDictionary savedState)
{
var name=System.Reflection.Assembly.GetExecutionGassembly().GetName().name;
RemoveKey(名称);
卸载(savedState);
}
私有void RemoveKey(字符串键)
{
尝试
{
Microsoft.Win32.RegistryKey注册表项=
Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@“软件\Microsoft\Windows\CurrentVersion\Run”,true);
regkey.DeleteValue(Key,false);
regkey.Close();
}
抓住
{
}
}
}
}
但它不起作用。实际上,我写的任何东西,不管它的内容是什么,似乎都不叫它。 我确认Uninstall方法确实被调用了,测试代码如下
MessageBox.Show(“卸载”)

我该怎么办?我觉得我应该找到其他不使用
.dll
的方法。我使用Visual Studio 2017。谢谢。

我注意到我的代码有点错误,因为Assembly.getExecutionGassembly()返回为.dll创建的项目名称(我的意思是,在本例中它返回“CustomAction”)。我修好了,但问题并没有解决。我想删除的RegistryKey仍然保留着…我认为Key是一个保留关键字,所以我首先要重命名它。很难提出任何建议,可能在捕获和运行过程监视器中添加一些错误日志,以查看注册表中发生的情况。谢谢您的评论。最后我发现Microsoft.Win32.Registry.CurrentUser在卸载时没有得到“HKEY_CURRENT_USER”,而是得到了“HKEY_USERS\.Default”,因此没有找到在“HKEY_CURRENT_USER”上注册的密钥。如果我知道如何获取“HKEY_CURRENT_USER”注册表项目录,我想我会解决这个问题。看起来这可能是你的问题:)哦,那会很有用的。我真的很感谢你的帮助!非常感谢。