WIX installer: How to create environment variable from vswhere.exe output
Hello,
I have a window installer XML (WIX) installer.
I use Visual Studio vswhere.exe to find out InstallationPath and InstanceId for further usage in my WIX code, see bellow:
<SetProperty Id="InstallationPathProf2019"
Value=""[SystemFolder]cmd.exe" /C ""[VS_INSTALLER_DIR_PATH]\vswhere.exe" -products Microsoft.VisualStudio.Product.Professional -property InstallationPath -version [\[]16.0,17.0[\)] > [TempFolder]InstallationPathProf2019.txt" && set /P VS_2019_INSTALLATIONPATH=<[TempFolder]InstallationPathProf2019.txt"
Before="InstallationPathProf2019" Sequence="execute" >NOT REMOVE="ALL"</SetProperty>
<CustomAction Id="InstallationPathProf2019" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Impersonate="no"/>
<SetProperty Id="InstanceIdProf2019"
Value=""[SystemFolder]cmd.exe" /C ""[VS_INSTALLER_DIR_PATH]vswhere.exe" -products Microsoft.VisualStudio.Product.Professional -property InstanceId -version [\[]16.0,17.0[\)] > [TempFolder]InstanceIdProf2019.txt && set /P VS_2019_INSTANCEID=<[TempFolder]InstanceIdProf2019.txt""
Before="InstanceIdProf2019" Sequence="execute" >NOT REMOVE="ALL"</SetProperty>
<CustomAction Id="InstanceIdProf2019" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Impersonate="no"/>
in addition, I use set directory with the value retrieved from vswhere as following:
<SetDirectory Id="APPLICATIONROOTDIRECTORY" Value="[%VS_2019_INSTALLATIONPATH]\Test" Sequence="execute" />
Which doesn't work - return empty string - MSI (c) (28:F8) [12:15:12:623]: PROPERTY CHANGE: Adding APPLICATIONROOTDIRECTORY property. Its value is '\Test'.
When I use predefind environment variable it work:
<SetDirectory Id="USERPROFILDIR" Value="[%USERPROFILE]\MyTest" Sequence="first" />
I see in log file:
PROPERTY CHANGE: Adding USERPROFILDIR property. Its value is 'C:\Users\donnam\MyTest'.
Why in my case it returns empty string? can't I set a value of environment variable and use it afterwards on my WIX code?
P.S. performing the above in CMD (not through WIX) I see environment variable is created:
I hope someone can help!
Thanks in advance!