Problem with Wix uninstall using CustomAction

戏子无情 提交于 2021-02-16 20:24:31

问题


I've created a very simple MSI which copies some files to the ProgramFiles directory and while installing calling to custom actions found in a binary written in C#.

While installing, I can easily call any custom action I want. For example I've created an installation step where the user should enter a license, and after confirming the license it is checked against a server using logic written inside C# custom action.

But, when uninstalling, every time I add a custom action (even if it does nothing but returning Success), I get error that the installation failed.

This is how I use the uninstalling step:

<InstallExecuteSequence>
  <Custom Action='TestUninstallation' After='MsiUnpublishAssemblies'>REMOVE="ALL"</Custom>
</InstallExecuteSequence>

where TestUninstallation is defined as following:

<CustomAction Id="TestUninstallation" Return="check" Execute="deferred" Impersonate="no" BinaryKey="TestCustomAction" DllEntry="Uninstall" />

The property DllEntry equals Uninstall which is a C# method which only returns Success.

After installation is completed, I'm trying to uninstall and I'm getting the UserExit dialog defined inside the AdminUISequence with the property OnExit.

Any idea what am I missing?


回答1:


Debugging: Managed code is relatively easy to debug (native code is actually even easier). Here are some pointers:

  • Debug C# Custom Actions (Advanced Installer)
  • Different debugging methods / aspects

Suggestions: I think you just have a broken reference to the dll export function - in other words an erroneous dll function name / reference:

<CustomAction Id="TestUninstallation" Return="check" Execute="deferred" Impersonate="no"
              BinaryKey="CustomActions" DllEntry="__ERRONEOUS FUNCTION REFERENCE__" />

Just check what the dll actually exports and match like this:

<CustomAction Id="CustomAction1" BinaryKey="CustomActions" DllEntry="CustomAction1"/>

As always the real McCoy is the check of the dll itself to see if you have the right function name (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:

Notice that this is a native dll with the managed code stuff embedded. It yields a very different functions list, but you still have to find the function name in there that you refer to.

This is a straight-up managed code dll (no native wrapping):

And finally: this is the straight-up managed code DLL without being wrapped in a native dll shell.


Un-Uninstallable Setup: When a custom action crashes or fails during uninstallation, you will have problems getting rid of the installation (it just rolls-back and you are stuck with it installed). There are several fixes or workarounds.

The overall fix - in my view - is to not fail custom actions on uninstall, or at least condition them so you can force an uninstall by setting a property via the command line:

Set in MSI property table: SUPPRESSERROR = 0. Then - when needed - on the command line set:

msiexec.exe /x {PRODUCT-GUID} SUPPRESSERROR="1"

Inside the MSI you condition the uninstall custom action with:

REMOVE="ALL" AND SUPPRESSERROR="0"

Now the custom action will not run if SUPPRESSERROR is anything but 0.

There is an older answer with several further options: I screwed up, how can I uninstall my program? (courtesy of Wim Coenen, with me messing up his answer with more suggestions).


Boilerplate: For quick use, let me just dump a boilerplate ad-hoc custom action test project here. This assumes a C# managed code custom action project called "CustomAction1" in the same Visual Studio solution and a reference added to it in your WiX source - like you already have obviously (this is for later when we have all forgotten what the problem was and need to test again):

<?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>
  1. Create WiX project
  2. Copy paste the code, set a new Upgrade GUID
  3. Create CustomAction project, default name
  4. Add reference to custom action project from wix project
  5. Add reference to WiXUIExtension.dll
  6. Adjust path to file in component
  7. Compile


来源:https://stackoverflow.com/questions/55205345/problem-with-wix-uninstall-using-customaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!