WIX installer: How to create environment variable from vswhere.exe output

DonnaMS 1 Reputation point


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="&quot;[SystemFolder]cmd.exe&quot; /C &quot;&quot;[VS_INSTALLER_DIR_PATH]\vswhere.exe&quot; -products Microsoft.VisualStudio.Product.Professional -property InstallationPath -version [\[]16.0,17.0[\)] > [TempFolder]InstallationPathProf2019.txt&quot; &amp;&amp; set /P VS_2019_INSTALLATIONPATH=&lt;[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="&quot;[SystemFolder]cmd.exe&quot; /C &quot;&quot;[VS_INSTALLER_DIR_PATH]vswhere.exe&quot; -products Microsoft.VisualStudio.Product.Professional -property InstanceId -version [\[]16.0,17.0[\)] > [TempFolder]InstanceIdProf2019.txt  &amp;&amp; set /P VS_2019_INSTANCEID=&lt;[TempFolder]InstanceIdProf2019.txt&quot;"  
               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!

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,173 questions
{count} votes