In my Wix installer I integrate MSVC redistributable runtime libraries instead of the full VC Redist packages because of smaller file size. On my machine these files are located in C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.38.33130\x86\Microsoft.VC143.CRT. Now I would like to get that path from a variable in Wix because the path will be different depending on Visual Studio edition, MSVC version, etc.
MSBuild offers a macro $(VC_CppRuntimeFilesPath_x86) which resolves to C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.38.33130\x86 from where I could easily build the correct path.
I tried the syntax from these instructions to capture the MSBuild macro into a Wix preprocessor variable.
<!-- Setup.wixproj -->
<Project Sdk="WixToolset.Sdk/4.0.3">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Label="Globals">
<DefineConstants>MsvcCrtX86=$(VC_CppRuntimeFilesPath_x86);MsvcCrtX64=$(VC_CppRuntimeFilesPath_x64);</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="WixToolset.UI.wixext" Version="4.0.3" />
</ItemGroup>
</Project>
<!-- Product.wxs -->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
...
<Fragment>
<ComponentGroup>
<Component Id="VCRT32" Directory="INSTALLFOLDER" Bitness="always32">
<File Source="$(var.MsvcCrtX86)\concrt140.dll" />
<File Source="$(var.MsvcCrtX86)\msvcp140.dll" />
<File Source="$(var.MsvcCrtX86)\msvcp140_1.dll" />
<File Source="$(var.MsvcCrtX86)\msvcp140_2.dll" />
<File Source="$(var.MsvcCrtX86)\msvcp140_atomic_wait.dll" />
<File Source="$(var.MsvcCrtX86)\msvcp140_codecvt_ids.dll" />
<File Source="$(var.MsvcCrtX86)\vccorlib140.dll" />
<File Source="$(var.MsvcCrtX86)\vcruntime140.dll" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Unfortunately, the MsvcCrtX86 and MsvcCrtX64 variables in Wix's preprocessor stay empty. My doubt is that MSBuild only populates $(VC_CppRuntimeFilesPath_x86) and similar macros for .vcxproj projects and not for SDK style projects.
You can check and execute a VC redist like below
Note the condition
VersionNT64 AND (NOT VC2015x64Installed OR VC2015x64BuildNumber < "31938"