PSMSI RunOnUninstall CustomActions different and not passing ScriptArguments?

Been a big fan of PowerShell Universal and bought it for work. Recently discovered PSMSI which I want to start utilizing but I seem to be running into an issue with CustomActions.

Trying to pass the same/similar ScriptArguments to RunOnUninstall doesn’t appear to work as RunOnInstall.

Looking at the generated WXS file shows two different PowerShell command methods (Install CustomAction = -File vs Uninstall Custom Action = -Command) and no ScriptArgument being passed for the Uninstall CustomAction:

<CustomAction Id=“CAf877bc71c53b4331ac4af05cc5d30941INSTALL” Property=“POWERSHELL” ExeCommand=“-NoExit -File "[#InstallScript]" -Message "Application Installed"" Return=“ignore” Execute=“deferred” />
<CustomAction Id=“CA2487b58486ae4f91b3d4c0ff74c440c7UNINSTALL” Property=“POWERSHELL” ExeCommand=”-NoExit -Command "{& ‘[#UninstallScript]’}"" Return=“ignore” Execute=“deferred” />

Shouldn’t it use the same method for each and the only difference be when it runs, on Install vs Uninstall?

@adam Is this a bug? Running a different type of command for RunOnInstall vs RunOnUninstall?

I think I found the issue in the PSMSI WixXmlGenerator.cs file on GitHub.

For RunOnInstall (line 103) it uses:

new XAttribute("ExeCommand", $"{customAction.Arguments} -File \"[#{customAction.FileId}]\" {customAction.ScriptArguments}"),

But for some reason RunOnUninstall (line 125) it uses a different action/command structure instead:

new XAttribute("ExeCommand", $"{customAction.Arguments} -Command \"{{& '[#{customAction.FileId}]'}}\""),

Can someone from IronmanSoftware update the PSMSI module so RunOnInstall and RunOnUninstall have matching action/command structures?

Nice catch. I can update this.

Thanks so much. You and your software rock for PowerShell!

1 Like