【问题标题】:Checking if a Property 'Starts/Ends With' in a csproj检查 csproj 中的属性是否“开始/结束”
【发布时间】:2012-05-28 12:33:07
【问题描述】:

我正在我的 csproj 文件中设置一些配置,这些配置将针对不同的框架版本。理想情况下,我想要“Debug - 3.5”、“Debug - 4.0”、“Release - 3.5”和“Release - 4.0”的配置。

在我的 csproj 文件中,我想做如下的事情:

<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} 是否以特定字符串开头/结尾。有没有简单的方法可以做到这一点?

编辑:下面标记的答案为我指明了正确的方向,这导致我继续:

<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

【问题讨论】:

标签: msbuild


【解决方案1】:

MSBuild 属性只是一个 .NET 字符串,并且有 property functions 可用。

Condition="$(Configuration.EndsWith('3.5'))"

应该有效

【讨论】:

  • 我要在这里冒险并假设“开始”是 `Condition="$(Configuration.StartsWith('blah'))" 因为这个答案没有覆盖这个。
  • 是的。例如,&lt;PropertyGroup Condition="$(Configuration.StartsWith('Debug'))"&gt; 将起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-29
  • 1970-01-01
  • 2018-11-20
  • 1970-01-01
  • 2021-11-13
相关资源
最近更新 更多