调试:托管代码相对容易调试(原生代码实际上更容易)。这里有一些提示:
建议:我认为您只有一个 broken reference to the dll export function - 换句话说,一个错误的 dll 函数名称/引用:
<CustomAction Id="TestUninstallation" Return="check" Execute="deferred" Impersonate="no"
BinaryKey="CustomActions" DllEntry="__ERRONEOUS FUNCTION REFERENCE__" />
只需检查 dll 实际导出的内容并像这样匹配:
<CustomAction Id="CustomAction1" BinaryKey="CustomActions" DllEntry="CustomAction1"/>
与往常一样,真正的 McCoy 是检查 dll 本身以查看您是否拥有正确的函数名称 (the below screen shot from this prior answer, recommended read)。
This is a native code C++ dll:
This is a DTF-packaged managed code dll:
请注意,这是一个嵌入了托管代码的本机 dll。它产生了一个非常不同的函数列表,但您仍然必须在其中找到您引用的函数名称。
This is a straight-up managed code dll (no native wrapping):
最后:这是直接托管代码 DLL,没有包装在本机 dll shell 中。
Un-Uninstallable Setup:当自定义操作在卸载过程中崩溃或失败时,您将无法摆脱安装(它只是回滚并且您正在坚持安装它)。有几个修复或解决方法。
在我看来,总体解决方法是在卸载时不使自定义操作失败,或者至少调整它们以便您可以通过命令行设置属性来强制卸载:
在 MSI 属性表中设置:SUPPRESSERROR = 0。然后 - 需要时 - 在命令行设置:
msiexec.exe /x {PRODUCT-GUID} SUPPRESSERROR="1"
在 MSI 中,您可以使用以下条件来调整卸载自定义操作:
REMOVE="ALL" AND SUPPRESSERROR="0"
现在如果 SUPPRESSERROR 不是 0,自定义操作将不会运行。
有一个较旧的答案,还有几个选项:I screwed up, how can I uninstall my program?(由Wim Coenen 提供,我把他的答案弄乱了,提供了更多建议)。
样板:为了快速使用,让我在这里转储样板即席自定义动作测试项目。这假设在同一个 Visual Studio 解决方案中有一个名为 "CustomAction1" 的 C# 托管代码自定义操作项目,并在您的 WiX 源代码中添加了一个引用 - 就像您显然已经拥有的那样(这是为了稍后我们有都忘记了问题是什么,需要再次测试):
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="WiXCustomActionsTesting" Language="1033" Version="1.0.0.0"
Manufacturer="test" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<UIRef Id="WixUI_Mondo" />
<Property Id="SUPPRESSERROR" Value="0" Secure="yes" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<Feature Id="ProductFeature" Title="WiXCustomActionsTesting" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<!--BEGIN CUSTOM ACTION SECTION-->
<Binary Id="CustomActions" SourceFile="$(var.CustomAction1.TargetDir)\$(var.CustomAction1.TargetName).CA.dll" />
<CustomAction Id="TestUninstallation" Return="check" Execute="deferred" Impersonate="no" BinaryKey="CustomActions" DllEntry="CustomAction1" />
<InstallUISequence></InstallUISequence>
<InstallExecuteSequence>
<Custom Action='TestUninstallation' After='InstallInitialize'></Custom>
</InstallExecuteSequence>
<!--END CUSTOM ACTION SECTION-->
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="WiXCustomActionsTesting" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component>
<File Source="C:\Projects\MySetup\MyApp.exe">
</File>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
- 创建 WiX 项目
- 复制粘贴代码,设置新的升级GUID
- 创建 CustomAction 项目,默认名称
- 从 wix 项目添加对自定义操作项目的引用
- 添加对 WiXUIExtension.dll 的引用
- 在组件中调整文件路径
- 编译