检查csproj中的属性“开始/结束于" [英] Checking if a Property 'Starts/Ends With' in a csproj
问题描述
我正在csproj文件中设置一些针对不同框架版本的配置.理想情况下,我需要配置调试-3.5",调试-4.0",发布-3.5"和发布-4.0".
I'm setting up some configurations in my csproj files that will target different framework versions. Ideally I want configurations of 'Debug - 3.5', 'Debug - 4.0', 'Release - 3.5' and 'Release - 4.0'.
在我的csproj文件中,我想要执行以下操作:
In my csproj file I want to do something like the following:
<PropertyGroup Condition=" '${Configuration}' ends with '3.5' ">
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup
<PropertyGroup Condition=" '${Configuration}' ends with '4.0' ">
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
</PropertyGroup
... check for "starts with Debug" to define Optimize etc.
但是,我不知道如何检查${Configuration}
是否以特定字符串开头/结尾.有没有简单的方法可以做到这一点?
However, I don't know how to go about checking that ${Configuration}
starts/ends with a particular string. Is there an easy way to do this?
编辑:以下标记为正确答案的答案,使我朝正确的方向前进:
Edit: Marked answer below for pointing me in the right direction, which lead me to go with:
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
... setup pdb, optimize etc.
</PropertyGroup>
<PropertyGroup Condition="$(Configuration.Contains('3.5'))">
... set target framework to 3.5
</PropertyGroup>
... and so on for Release and 4.0 variations
推荐答案
An MSBuild property is just a .NET String and has property functions available.
Condition="$(Configuration.EndsWith('3.5'))"
应该工作
这篇关于检查csproj中的属性“开始/结束于"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!