Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new property in MSBuild and reference it in WIX

We need to create a property to indicate our software version. Then we want to use it inside our WIX project, i.e., reference it in wxs file. We don't want to define it in wxs file because we want the MSBuild to rename output file based on this version number too. A definition of constants in PropertyGroup is not a proper place for us and here is the reason:

The properties defined in the PropertyGroup is Configuration/Platform specific. Whenever we modify this preprocessor in Visual Studio IDE from project properties window, normally we only modify the value for a specific Configuration/Platform combination. (I know it is possible to modify it for All Config/Platform in IDE, but it is actually done by making copies to all combinations. And it is still possible we ruin the synchronization by modifying a value for only one combination. For example, by default when we open the build tab of project properties window, it will show the active Config/Platform). On the other hand, even though we can define a PropertyGroup without any condition, whenever we modify it in the IDE, we are normally only modifying it for the specific combination, not all of them. Since we are purely building our SW in VS IDE, it will be hard to maintain and prone to problem.

I tried to use CreateProperty task of MSBuild inside BeforeBuild target, but it seems in the following execution the value will not be effective at all. For example, if I overwrite an existing property in BeforeBuild, and when I reference it in WIX, it will still use the old value. And if I create a totally new property, WIX is complaining undefined preprocessor.

Is there a proper way to do that: create a MSBuild property and use it inside WIX?

like image 641
tete Avatar asked Nov 06 '12 11:11

tete


People also ask

How do I set properties in MSBuild?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.

What is Property Group in MSBuild?

Contains a set of user-defined Property elements. Every Property element used in an MSBuild project must be a child of a PropertyGroup element. <Project> <PropertyGroup>


1 Answers

You don't need to use BeforeBuild. This definitely works on wixproj.

my.properties

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <DefineConstants>$(DefineConstants);foo=bar</DefineConstants>
  </PropertyGroup>
</Project>

updated wixproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- all other stuff -->
<Import Project="my.properties" />
</Project>

Wix

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="SetupProject1$(var.foo)" Language="1033" Version="1.0.0.0" Manufacturer="$(var.foo)" UpgradeCode="863d8da1-422b-4b28-aa68-56e3190770d7">
like image 167
fsimonazzi Avatar answered Nov 13 '22 13:11

fsimonazzi