I want to make an installer run a PowerShell script, before installing all the other files. However, how it is build currently, it only works to run the script when the install is done, because it is placing the powershell script in the target directory. Now this could probably be fixed by making the directory something that is always existing. However, I don't want to have to provide the script with the installer all the time, I want the script to be embedded into the installer and run from there or at least run the commands that are in the script file.
I tried changing the custom action's "After" to "InstallInitialize", however it throws an error saying it can't the path (which is logical, because the path isn't created yet because the script is executed before the installation of the files).
Here is a bit of the code where all the logic for running the powershell script is provided:
<DirectoryRef Id="INSTALLFOLDER">
<Component Id ="SOMESCRIPT" Guid="">
<File Id="SOMESCRIPT" Name="My-Script.ps1" Source="My-Script.ps1" />
</Component>
</DirectoryRef>
<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>
<SetProperty Id="PSscript"
After="PSscript"
Sequence="execute"
Value =""[POWERSHELLEXE]" -Version 3.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[#SOMESCRIPT]' ; exit $$($Error.Count)"" />
<CustomAction Id="PSscript"
BinaryKey="WixCA"
DllEntry="WixQuietExec"
Execute="deferred"
Return="check"
Impersonate="yes" />
<InstallExecuteSequence>
<Custom Action="PSscript" After="InstallInitialize"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>
The Expected result is the script being embedded into the .msi file, not relying on a file that is only created after installation. The error message is that it can't find the script because it isn't installed yet. I actually don't want the script file to be placed in the folder to begin with, I just want the script run inside the installer and do nothing else with the script file.