使用 MSBuild 将多个值传递给 Wix DefineConstants 属性 [英] Passing multiple values to Wix DefineConstants property with MSBuild

查看:23
本文介绍了使用 MSBuild 将多个值传递给 Wix DefineConstants 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将我的 Wix 项目集成到 MSBuild 中.我有必要将多个值传递给 Wix 项目.一个值将起作用(下面示例中的 ProductVersion).

I'm currently integrating my Wix projects in MSBuild. It is necessary for me to pass multiple values to the Wix project. One value will work (ProductVersion in the sample below).

<Target Name="BuildWixSetups">
    <MSBuild Condition="'%(WixSetups.Identity)'!=''"
                Projects="%(WixSetups.Identity)"
                Targets="Rebuild" Properties="Configuration=Release;OutputPath=$(OutDir);DefineConstants=ProductVersion=%(WixSetups.ISVersion)" ContinueOnError="true"/>
</Target>

但是,如何将多个值传递给 DefineConstants 键?我已经尝试了所有逻辑"分隔符(空格、逗号、分号、管道符号),但这不起作用.

However, how do I pass multiple values to the DefineConstants key? I've tried all the 'logical' separators (space, comma, semi-colon, pipe-symbol), but this doesn't work.

有其他人遇到过这个问题吗?

Has someone else come across this problem?

不起作用的解决方案:

  1. 尝试添加 DefineConstants 元素不起作用,因为 DefineConstants 需要在 Properties 属性中表示.

推荐答案

问题:

MSBuild 任务(不是 MSBuild.exe,名为 MSBuild 的 MSBuild 任务)无法处理 WIX 项目使用的多个常量.通常,您会在构建脚本中指定属性,例如:

The MSBuild task (not MSBuild.exe, the MSBuild task named MSBuild) cannot handle multiple constants used by WIX projects. Normally you would specify the properties in your build script like:

<MSBuild Projects="YourSolution.sln" Properties="Configuration=MyConfig;Platform=x86;DefineConstants=&quot;SOMETHING=1;SOMETHINGELSE=2&quot;" />

但是,当您查看构建日志时,您会看到 MSBuild 将常量分开,并且不会像您期望的那样将值组合在一起 - 类似于:

What you see however, when looking at the build logs is the MSBuild separates the constants and does not keep the values grouped together like you would expect - similar to:

Task "MSBuild" Global Properties:
Configuration=MyConfig
Platform=x86
DefineConstants="SOMETHING=1
SOMETHINGELSE=2"

因此,当蜡烛尝试使用这些常量时,它通常会响应错误 CNDL0150:未定义的预处理器变量 '$(var.SOMETHINGELSE)'.这意味着 MSBuild 任务没有正确处理包含多个="的属性即使分组在引号中的值.如果没有将属性值分组在引号中,它们显然应该被视为单独的属性,而不是单个值.

So when candle tries to use those constants it typically responds with "error CNDL0150: Undefined preprocessor variable '$(var.SOMETHINGELSE)'. What this means is the MSBuild task is not properly handling properties which contain multiple '=' in the value even when grouped within quotation marks. Without the property value being grouped in quotation marks, they should obviously be treated as separate properties, rather than a single value.

解决方法:

为了解决这个问题,您需要直接调用 MSBuild.exe 并手动将这些值传递给它.

In order to fix this problem, you need to call MSBuild.exe directly and pass those values to it manually.

msbuild.exe /p:Configuration=MyConfig /p:Platform=x86 /p:DefineConstants="SOMETHING=1;SOMETHINGELSE=2" YourSolution.sln

这将使您的常量以您希望的方式工作,而无需重新设计您的 WiX 安装项目.

This will get your constants the work the way you want them to, without having to redesign your WiX installation project.

注意:如果您只使用一个常量,您仍然可以像这样使用 MSBuild 任务:

NOTE: If you're only using a single constant you can still use the MSBuild task like so:

<MSBuild Projects="YourSolution.sln" Properties="Configuration=MyConfig;Platform=x86;DefineConstants=&quot;SOMETHING=1&quot;" />

这篇关于使用 MSBuild 将多个值传递给 Wix DefineConstants 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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