Search code examples
powershellwixwix3.5

WIX - Reference a heat generated file ID for use in Custom Action


New to Wix, but trying to learn!

I'm using heat to generate a 'directory.wxs' file that contains all of the files I need for my application. One of these files is a Powershell script that I need to run as a custom action. I'm trying to use the -suid flag so the File Id is consistent across runs. I don't like this solution as I may be in a bad way if I ever have two files with the same name... suggestions welcome on that one.

In the customaction.wxs file, I'm trying to use what is generated, "install-service-filebeat.ps1" as my Property value in my custom action. I have looked at a quite a few examples / problems similar to this across here and other sites. I may just be an idiot and missing something, but was wondering if my issue is with referencing the ID from my directory.wxs file, or if it elsewhere in my syntax.

Below are my scripts, I included them at the end as they are long.

Thanks in advance!

My PS script:

## Powershell Script to Create MSI ##

## Variables ##

# WIX Source Dir #
$WIX_DIR="C:\Program Files (x86)\WiX Toolset v3.11\bin"

# Source Dir for files to be enumerated into MSI #
$SRC_DIR="C:\application-directory"


# Name of our Application #
$APP_NAME="Filebeat"

# Where to stage the various .wxs files #
$STG_DIR="C:\wix-project\${APP_NAME}\stage"

# Where to deliver the Final Product #
$TGT_DIR="C:\wix-project\${APP_NAME}\output"

## Create MSI ##

# Compile the source files into a Fragment to be referenced by main builder Product.wxs #
& ${WIX_DIR}\heat.exe dir $SRC_DIR -srd -dr INSTALLDIR -cg MainComponentGroup -out ${STG_DIR}\directory.wxs -ke -sfrag -gg -ssuid -var var.SourceDir -sreg -scom

# Convert the .wxs files into .wxobj for consumption by light.exe #
& ${WIX_DIR}\candle.exe -dSourceDir="${SRC_DIR}" ${STG_DIR}\*.wxs -o ${STG_DIR}\ -ext WixUtilExtension -arch x64

# Create the final MSI package --CURRENTLY REFERENCING THE FILES EXPLICITY. NEED TO FIND WAY TO WILDCARD! #
& ${WIX_DIR}\light.exe -o ${TGT_DIR}\${APP_NAME}_installer.msi ${STG_DIR}\customaction.wixobj ${STG_DIR}\directory.wixobj ${STG_DIR}\product.wixobj -cultures:en-US -ext WixUIExtension.dll -ext WiXUtilExtension.dll

This generates my files just fine, and compiles them. The contents of my customaction.wxs:

<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>
 <Fragment>
 <!--Define the CustomAction for running the PowerShell script-->
<CustomAction Id="RunPowerShellScript_set"
              Property="install_service.ps1"
              Value="&quot;[\[]POWERSHELLEXE[\]]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp;'4(var.SourceDir)\[\[]#install_service.ps1[\]]'; exit $$($Error.Count)&quot;" />

 <CustomAction Id="RunPowerShellScript"
               BinaryKey="WixCA"
               DllEntry="CAQuietExec"
               Execute="deferred"
               Return="check"
               Impersonate="yes" />

  <!-- Ensure PowerShell is installed and obtain the PowerShell executable location -->
  <Property Id="POWERSHELLEXE">
    <RegistrySearch Id="POWERSHELLEXE"
                    Type="raw"
                    Root="HKLM"
                    Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
                    Name="Path" />
  </Property>

  <Condition Message="This application requires Windows PowerShell.">
    <![CDATA[Installed OR POWERSHELLEXE]]>
  </Condition>

 </Fragment>
</Wix>

And the relevant portion of my product.wxs:

<!-- Execute Custom Action -->
        <InstallExecuteSequence>
          <Custom Action="RunPowerShellScript_set" After="InstallFiles" />
         <Custom Action="RunPowerShellScript" After="InstallFiles">
           <![CDATA[NOT Installed]]>
         </Custom>
        </InstallExecuteSequence>

Solution

  • I think that your Property="install_service.ps1" is incorrect. Try to follow the pattern from my blog post. I hope it helps you, just tested my script again and it works. Have a nice day!