ylbtech-Docs-VisualStudio-MSBuild-MSBuild参考:MSBuild 条件构造 |
1.返回顶部 |
MSBuild 为非此即彼的处理机制提供 Choose、When 和 Otherwise 元素。
Choose
元素包含一系列具有 Condition
属性的 When
元素,这些元素按照从顶部到底部的顺序进行测试,直到一个元素的计算结果为 true
。 如果多个 When
元素的计算结果为 true
,则只使用第一个。 如果 When
元素的任何条件的计算结果均为 true
,则评估 Otherwise
元素(如存在)。
Choose
元素可用作 Project
、When
和 Otherwise
元素的子元素。 When
和 Otherwise
元素可具有 ItemGroup
、PropertyGroup
或 Choose
子元素。
以下示例使用 Choose
和 When
元素进行非此即彼的处理。 根据 Configuration
属性的值设置项目的属性和项。
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" > <PropertyGroup> <Configuration Condition=" ‘$(Configuration)‘ == ‘‘ ">Debug</Configuration> <OutputType>Exe</OutputType> <RootNamespace>ConsoleApplication1</RootNamespace> <AssemblyName>ConsoleApplication1</AssemblyName> <WarningLevel>4</WarningLevel> </PropertyGroup> <Choose> <When Condition=" ‘$(Configuration)‘==‘Debug‘ "> <PropertyGroup> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>.\bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> </PropertyGroup> <ItemGroup> <Compile Include="UnitTesting\*.cs" /> <Reference Include="NUnit.dll" /> </ItemGroup> </When> <When Condition=" ‘$(Configuration)‘==‘retail‘ "> <PropertyGroup> <DebugSymbols>false</DebugSymbols> <Optimize>true</Optimize> <OutputPath>.\bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> </PropertyGroup> </When> </Choose> <!-- Rest of Project --> </Project>
在此示例中,使用了关于编译器常量 DEFINED_CONSTANT
的条件。 这些内容包含在 DefinedConstants
属性中。 正则表达式用于匹配分号分隔列表中的确切常量。
<Choose> <When Condition="$([System.Text.RegularExpressions.Regex]::IsMatch( $(DefineConstants), ‘^(.*;)*DEFINED_CONSTANT(;.*)*$‘))"> <!-- When DEFINED_CONSTANT is defined. --> </When> <!-- other conditions --> </Choose>
2.返回顶部 |
3.返回顶部 |
4.返回顶部 |
5.返回顶部 |
6.返回顶部 |
![]() |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
Docs-VisualStudio-MSBuild-MSBuild参考:MSBuild 条件构造
原文:https://www.cnblogs.com/storebook/p/13391287.html