调试:托管代码相对容易调试(本机代码实际上更容易)。以下是一些提示:
-
调试 C# 自定义操作 (高级安装程序)
- 不同的调试方法/方面
建议: 我想你只是有一个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 本身,看看你是否有正确的函数名称(下面的屏幕截图来自之前的答案,建议阅读).
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 中。
不可卸载的安装程序:当自定义操作在卸载过程中崩溃或失败时,您将在删除安装时遇到问题(它只是回滚,您将无法继续安装)。有多种修复或解决方法。
在我看来,总体修复是在卸载时不要使自定义操作失败,或者至少调节它们,以便您可以通过命令行设置属性来强制卸载:
在MSI属性表中设置:SUPPRESSERROR = 0
。然后 - 当需要时 - 在命令行上设置:
msiexec.exe /x {PRODUCT-GUID} SUPPRESSERROR="1"
在 MSI 中,您可以使用以下命令来调节卸载自定义操作:
REMOVE="ALL" AND SUPPRESSERROR="0"
现在,如果 SUPPRESSERROR 不是 0,则自定义操作将不会运行。
有一个较旧的答案,其中有几个进一步的选项:我搞砸了,如何卸载我的程序?(由维姆·科南,我用更多的建议搞乱了他的答案)。
样板文件:为了快速使用,让我在这里转储一个样板临时自定义操作测试项目。这假设有一个名为的 C# 托管代码自定义操作项目"CustomAction1"
在同一个 Visual Studio 解决方案中,并在 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 项目
- 复制粘贴代码,设置新的升级指南
- 创建CustomAction项目,默认名称
- 添加对 wix 项目中的自定义操作项目的引用
- 添加对 WiXUIExtension.dll 的引用
- 调整组件中文件的路径
- Compile