如何在MSBuild中创建新属性并在WIX中引用它 [英] How to create a new property in MSBuild and reference it in WIX

查看:93
本文介绍了如何在MSBuild中创建新属性并在WIX中引用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要创建一个属性来指示我们的软件版本.然后我们要在WIX项目中使用它,即在wxs文件中引用它.我们不想在wxs文件中定义它,因为我们也希望MSBuild也根据该版本号重命名输出文件. PropertyGroup中常量的定义对我们来说不合适,这是原因:

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:

在PropertyGroup中定义的属性是Configuration/Platform特定的.每当我们从项目属性窗口在Visual Studio IDE中修改此预处理器时,通常只修改特定Configuration/Platform组合的值. (我知道可以在IDE中为All Config/Platform修改它,但实际上是通过对所有组合进行复制来完成的.并且仍然有可能通过仅修改一个组合的值来破坏同步.例如,默认情况下,当我们打开项目属性窗口的构建选项卡时,它将显示活动的Config/Platform.另一方面,即使我们可以在没有任何条件的情况下定义PropertyGroup,但是只要在IDE中对其进行修改,我们通常只会针对特定的组合(而不是所有组合)进行修改.由于我们纯粹是在VS IDE中构建软件,因此将很难维护并且容易出现问题.

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.

我尝试在BeforeBuild目标中使用MSBuild的CreateProperty任务,但是在以下执行中,该值似乎根本无效.例如,如果我覆盖BeforeBuild中的现有属性,并且在WIX中引用它时,它仍将使用旧值.而且,如果我创建一个全新的属性,则WIX会抱怨未定义的预处理器.

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.

是否有正确的方法:创建MSBuild属性并在WIX中使用它?

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

推荐答案

您不需要使用BeforeBuild.这绝对适用于wixproj.

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

my.properties

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>

更新了wixproj

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>

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

这篇关于如何在MSBuild中创建新属性并在WIX中引用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆