32

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'.

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.

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
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Adam Rodger
  • 3,472
  • 4
  • 33
  • 45
  • Tagged this [msbuild] for you, a csproj file is just an msbuild file and the additional tag might get some msbuild expert attention. – Jamiec May 28 '12 at 12:35
  • possible duplicate of [Is there any MSbuild task to check if a string contains another string (similar to string.contains)](http://stackoverflow.com/questions/3289538/is-there-any-msbuild-task-to-check-if-a-string-contains-another-string-similar) – Daniel A. White May 28 '12 at 12:36

1 Answers1

74

An MSBuild property is just a .NET String and has property functions available.

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

Should work

Damian Edwards
  • 7,289
  • 1
  • 25
  • 19
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216