A user comment recently alerted me to the need to update a past article I wrote on integrating MSBuild and WiX so that one might achieve build automation with WiX. My previous article was written a long time ago, and probably was done before actually implementing the process in practice.
How I actually integrated WiX with MSBuild in the real world will be shown in this post.
Let’s assume you want to set up WiX so that MSBuild can pass some variables to it (a good example being the product version; let’s assign that to a constant named PRODUCTVERSION).
In your WiX source, you’d reference that passed-in product version using:
To get that to work, the first thing I do is edit the *.wixproj file itself. Place the following somewhere in the file (mine is at the bottom about):
<Target Name="BeforeBuild"> <CreateProperty Condition="$(PRODUCTVERSION) != ''" Value="PRODUCTVERSION=$(PRODUCTVERSION);$(DefineConstants)"> <Output TaskParameter="Value" PropertyName="DefineConstants" /> </CreateProperty> </Target>
Then, in your msbuild/team build script, you can build the WiX project and pass in the product version like so:
<MSBuild Projects="$(PathToProjectFolder)\YourProject.wixproj" Properties="PRODUCTVERSION=$(YourProductVersion)" />
Naturally, you need to define the “PathToProjectFolder” and “YourProductVersion” somewhere.
Also, if you want to pass additional properties, they should be semicolon delimited when setting the “Properties” attribute.