Wednesday, 23 January 2019

Wix Installer Issues

Following are some common issues often faced by developers while developing the windows installer using wix.


1. Adding assemblies to GAC: Bellow is the simple code example to add the assembly into GAC:

Adding the target output dll to GAC:
<Component Guid="1bb847ef-912a-49b0-9e32-7788e2b5a6c1" Id="ProductComponentGAC" Directory="GAC">
        <File Id="aPersonaDLLGAC" Name="aPersona_AMFA.dll" Assembly=".net" KeyPath="yes" Source="$(var.aPersona_AMFA.TargetPath)" />
</Component>

Adding the other 3rd party dlls into GAC:
<Component Id="NewtonsoftGACComponent" Directory="GAC">
        <File Id="newtonsoftDLLGAC" KeyPath="yes" Assembly=".net" Source="$(var.aPersona_AMFA.ProjectDir)\bin\Debug\Newtonsoft.Json.dll" />
</Component>

2. Adding assemblies to setup folder those are also added in GAC: Often assemblies that we included into GAC, doesn't add into the setup folder. For this solution we have following code:
<Component Guid="1bb847ef-912a-49b0-9e32-7788e2b5a6c0" Id="ProductComponent" Directory="INSTALLFOLDER">
        <File Id="aPersonaDLL" Source="$(var.aPersona_AMFA.TargetPath)" />
        <File Id="newtonsoftDLL" Source="$(var.aPersona_AMFA.ProjectDir)\bin\Debug\Newtonsoft.Json.dll" />
        <File Id="mfstIdentityServerDLL" Source="$(var.aPersona_AMFA.ProjectDir)\bin\Debug\Microsoft.IdentityServer.Web.dll" />
</Component>

3. Execute powershell commands after installing or uninstalling the setup: Bellow is the code to run the powershell commands after successfully installed or uninstalled the Installer.

<!--BEGIN: Custom Actions-->
<CustomAction Id="RegisterPSCmd"
Property="RegisterPowerShellProperty"
Value="&quot;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NoLogo -NonInteractive -InputFormat None -NoProfile -File &quot;C:\Program Files (x86)\aPersonaAdfsAdapter\RegisterPlugin.ps1&quot; &quot;arg_that_I_maybe_require_for_my_script&quot;"
Execute="immediate" />
<CustomAction Id="RegisterPowerShellProperty"
              BinaryKey="WixCA"
              DllEntry="CAQuietExec64"
              Execute="commit"
              Return="check"
              Impersonate="no" />

<CustomAction Id="RegisterPSCmdUninstall"
Property="RegisterPowerShellPropertyUninstall"
Value="&quot;C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe&quot; -NoLogo -NonInteractive -InputFormat None -NoProfile -File &quot;C:\Program Files (x86)\aPersonaAdfsAdapter\UnregisterPlugin.ps1&quot; &quot;arg_that_I_maybe_require_for_my_unistallscript&quot;"
Execute="immediate" />
<CustomAction Id="RegisterPowerShellPropertyUninstall"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="no" />

<InstallExecuteSequence>
      <Custom Action="RegisterPSCmd" After="CostFinalize">NOT  Installed</Custom>
      <Custom Action="RegisterPowerShellProperty" After="InstallFiles">NOT Installed</Custom>
      <Custom Action='RegisterPSCmdUninstall' Before='CostInitialize'>(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
      <Custom Action='RegisterPowerShellPropertyUninstall' Before='RemoveFiles'>(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
</InstallExecuteSequence>
<!--END: Custom Actions-->

Note: You can download the complete working demo using the bellow link:Download Working Demo



No comments:

Post a Comment