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

╄→尐↘猪︶ㄣ 提交于 2019-12-10 14:37:01

问题


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?


回答1:


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">



回答2:


Please check preprocessor variables here. I'm not sure actually if you can reference project properties other than standard, but looks like it is possible.



来源:https://stackoverflow.com/questions/13250120/how-to-create-a-new-property-in-msbuild-and-reference-it-in-wix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!