问题描述
我陷入了这样一种情况,即我有一个 MSBuild 脚本需要读取项目的构建属性中设置的条件编译符号.我的 MSBuild 脚本文件中有以下代码
I am stuck in a situation where I have an MSBuild script that needs to read the conditional compilation symbols set in project's build property. I have the following code in my MSBuild script file
<PropertyGroup>
<DefineConstants>$(DefineConstants);INTER</DefineConstants>
</PropertyGroup>
<Target Name="Compile">
<Message Text="$(DefineConstants)"/>
<MSBuild Projects="CustomAssemblyInfo.csproj" Targets="Rebuild" Properties="DefineConstants=$(DefineConstants)" />
</Target>
我假设 $(DefineConstants);将包含设置的条件编译符号的值,我可以在这些值之后附加任何内容,例如在这种情况下 INTER 但不知何故,项目属性中设置的值没有在这里传递.任何人都可以帮助我错过什么吗?
I was assuming that the $(DefineConstants); will contain the value of conditional compilation symbols that are set and I can just append anything after those values like in this case INTER but somehow the values set in the project properties are not getting passed here. Can anyone please help in what am I missing?
推荐答案
通过MSBuild任务的Properties属性传递的属性就是所谓的global属性,与在命令行中使用 /p: 传递的属性相同.它们优先于任何其他属性或环境变量,即使是那些无条件定义的,即 .csproj 中的 DefineConstants.
Properties passed via Properties property of MSBuild task are what's called global properties, same as those passed with /p: on command line. They take priority over any other property or environment variable even those defined unconditionally, i.e. the DefineConstants in your .csproj.
通过首先传递您自己的 DefineConstants,您可以防止以后从 .csproj 设置它,因此要防止它添加类似 $(Constants) 在您的项目属性窗口中将 DefineConstants 重新定义为 <DefineConstants>TRACE;DEBUG;$(Constants)</DefineConstants> 并传递 Constants 来自您的 MSBuild/NAnt 脚本.
By passing your own DefineConstants first you prevent it being set later from the .csproj, so to prevent it add something like $(Constants) in your project properties window which would redefine DefineConstants as <DefineConstants>TRACE;DEBUG;$(Constants)</DefineConstants> and pass Constants from your MSBuild/NAnt script instead.
根据下面的@s 评论
As per @s comment below
https://i.imgur.com/jZiVy7J.png
这篇关于如何使用 MSBuild 在项目属性中附加条件编译符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)