Wix 中的 C# 自定义操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1213953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 11:05:47  来源:igfitidea点击:

C# custom action in Wix

c#wixwix3custom-action

提问by Amith George

When my application is uninstalled, the server needs to be notified so that it can free up the license key assigned to the client. This is done via a web service call.

当我的应用程序被卸载时,需要通知服务器,以便它可以释放分配给客户端的许可证密钥。这是通过 Web 服务调用完成的。

I created a C# custom action that does this. The problem is, the uninstaller is quitting saying that it couldnt find a dll.

我创建了一个 C# 自定义操作来执行此操作。问题是,卸载程序退出说它找不到 dll。

The error log for the msi contains the following error:

msi 的错误日志包含以下错误:

Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor. Action ReadLicenseKeyFromFile, entry: ReadLicenseKey, library: C:\Windows\Installer\MSI4F42.tmp

错误 1723。此 Windows 安装程序包有问题。无法运行此安装完成所需的 DLL。请联系您的支持人员或软件包供应商。操作 ReadLicenseKeyFromFile,条目:ReadLicenseKey,库:C:\Windows\Installer\MSI4F42.tmp

I have the function ReadLicenseKey marked as a custom action. The custom action is named ReadLicenseKeyFromFile.

我将函数 ReadLicenseKey 标记为自定义操作。自定义操作名为 ReadLicenseKeyFromFile。

<Custom Action="ReadLicenseKeyFromFile" After="InstallInitialize">
    REMOVE~="ALL" AND NOT UPGRADINGPRODUCTCODE
</Custom>

<CustomAction Id="ReadLicenseKeyFromFile" BinaryKey="UnInstallCA.CA.dll" DllEntry="ReadLicenseKey" Execute="immediate" Return="check" />

<Binary Id="UnInstallCA.CA.dll" SourceFile="$(var.UnInstallCA.TargetDir)UnInstallCA.CA.dll" />

The custom action project is outputting the .CA.dll file. I have tried installing the file as a part of the setup, manually copy pasted the file, done nothing to the file... basically tried all possible combinations.

自定义操作项目正在输出 .CA.dll 文件。我尝试将文件安装为安装程序的一部分,手动复制粘贴文件,对文件没有做任何事情......基本上尝试了所有可能的组合。

There must be something that I am missing, so please help.

一定有我遗漏的东西,所以请帮忙。

采纳答案by Amith George

Am sorry to have wasted everyone's time over this.

很抱歉在这上面浪费了大家的时间。

The solution was something rather too simple. I had forgotten to place the [CustomAction] attribute on this particular method. So even though it was the last action which I had written in my CustomAction.cs file, it was the first one to be called in the InstallExecuteSequence. And because of that, I got misled in to thinking that it couldnt find the file. Well, that as well as the fact that I must have been really sleepy...

解决方案太简单了。我忘记将 [CustomAction] 属性放在此特定方法上。因此,即使这是我在 CustomAction.cs 文件中编写的最后一个操作,它也是在 InstallExecuteSequence 中调用的第一个操作。正因为如此,我误以为它找不到文件。好吧,还有我一定是真的很困的事实......

Anyway, while searching for the answer I did manage to come across lots of nice resources, especially Alex Shevchuks series on Wix. Another thing I realised was that I dont have to install the custom action dll file. I just have reference it from my Wix project and provide the path to it. The dll gets embedded in the setup and is streamed from there when the uninstall custom actions is to be called.

无论如何,在寻找答案时,我确实遇到了很多不错的资源,尤其是关于 Wix 的 Alex Shevchuks 系列。我意识到的另一件事是我不必安装自定义操作 dll 文件。我只是从我的 Wix 项目中引用它并提供它的路径。dll 嵌入到安装程序中,并在调用卸载自定义操作时从那里流式传输。

回答by da_m_n

Is your UnInstallCA.CA.dll copied to the target machine during install? It seems that it's not there at uninstall.

在安装过程中,您的 UnInstallCA.CA.dll 是否已复制到目标计算机?似乎在卸载时它不存在。

If it got there - can it run? ( try running it from the target machine to see if it can do what it's supposed to do - maybe you need to ship some other dll you're using from this one - or maybe some redistributable package )

如果它到达那里 - 它可以运行吗?(尝试从目标机器运行它,看看它是否可以做它应该做的事情——也许你需要从这个机器上发布一些你正在使用的其他 dll——或者一些可再发行的包)