Reputation: 2409
Wix 3.11.2
I have variables that are defined as properties in my .wixproj file or imported via other .props files, but when they're referenced within the .wxs file, Candle throws an error.
In my minimal repro, my wixproj is completely unchanged from what gets generated by the Visual Studio 2022 extension, save for defining the variable and adding a single .wxs file:
<PropertyGroup>
<Manufacturer>ReproManufacturer</Manufacturer>
</PropertyGroup>
<ItemGroup>
<Compile Include="Product.wxs" />
</ItemGroup>
and the entirety of Product.wxs is:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="MinimalRepro" Language="1033" Version="1.0.0.0" Manufacturer="$(var.Manufacturer)" UpgradeCode="8ad3f73f-4be0-410a-aad0-ec2057962a2f">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
</Product>
</Wix>
When building (both within VS and via commandline with just msbuild
), I get this error:
CNDL0150: Undefined preprocessor variable '$(var.Manufacturer)'.
In the build logs, it's not defined when candle.exe is called:
candle.exe
-dDebug
-d"DevEnvDir=C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\\"
-d"SolutionDir=*Undefined if not building a solution or within Visual Studio*"
-d"SolutionExt=*Undefined if not building a solution or within Visual Studio*"
-d"SolutionFileName=*Undefined if not building a solution or within Visual Studio*"
-d"SolutionName=*Undefined if not building a solution or within Visual Studio*"
-d"SolutionPath=*Undefined if not building a solution or within Visual Studio*"
-dConfiguration=Debug
-dOutDir=bin\Debug\
-dPlatform=x86
-dProjectDir=C:\Path\
-dProjectExt=.wixproj
-dProjectFileName=MinimalRepro.wixproj
-dProjectName=MinimalRepro
-dProjectPath=C:\Path\MinimalRepro.wixproj
-dTargetDir=C:\Path\bin\Debug\
-dTargetExt=.msi
-dTargetFileName=MinimalRepro.msi
-dTargetName=MinimalRepro
-dTargetPath=C:\Path\bin\Debug\MinimalRepro.msi
-out obj\Debug\
-arch x86
Product.wxs
If I define them within a .wxi file, then it works... but I need to pull some values from properties, so that work-around doesn't work for me.
I'm not sure what I'm missing; any ideas?
Update:
If I also add this to my wixproj file:
<Target Name="DefineConstants">
<PropertyGroup>
<DefineConstants>$(DefineConstants);Manufacturer=TargetManufacturer</DefineConstants>
</PropertyGroup>
</Target>
and add it to the InitialTargets
list within the <Project>
tag, then it works as expected. Not ideal, but functional. I'm still hoping to figure out how to get it working without having to add every property manually.
Upvotes: 0
Views: 585
Reputation: 35996
MSBuild properties are not WiX preprocessor defines. However, as you found, the WiX MSBuild targets will convert the single MSBuild property DefineConstants
into WiX preprocessor defines. You shouldn't need a Target to do this. Just do:
<PropertyGroup>
<DefineConstants>Manufacturer=ReproManufacturer</DefineConstants>
</PropertyGroup>
Or if you must have an MSBuild property involved:
<PropertyGroup>
<Manufacturer>ReproManufacturer</Manufacturer>
<DefineConstants>Manufacturer=$(Manufacturer)</DefineConstants>
</PropertyGroup>
Upvotes: 2