How to append conditional compilation symbols in project properties with MSBuild?(如何使用 MSBuild 在项目属性中附加条件编译符号?)
问题描述
我陷入了这样一种情况,即我有一个 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 在项目属性中附加条件编译符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 MSBuild 在项目属性中附加条件编译符号
基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01