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

查看:124
本文介绍了使用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"

因此,当Candle尝试使用这些常量时,它通常会响应错误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天全站免登陆