1

I have read this question but now that we also have 4.5 the solution won't work.
How can I check if the runtime is above 4.0?
Since it's a string I am guessing I cannot do:

<DefineConstants Condition=" '$(TargetFrameworkVersion)' >= 'v4.0' ">NET_4_0</DefineConstants>

So should I define both:

<DefineConstants Condition=" '$(TargetFrameworkVersion)' == 'v4.0' ">NET_4_0</DefineConstants>
<DefineConstants Condition=" '$(TargetFrameworkVersion)' == 'v4.5' ">NET_4_5</DefineConstants>

Is there a more generic solution?

Community
  • 1
  • 1
the_drow
  • 18,571
  • 25
  • 126
  • 193
  • The `>` and `<` operators only work on strings that contain numbers, the "v" screws that up. I see nothing wrong with your workaround, albeit that you probably just want to treat 4.5 as 4.0, allowing OR. You could also use ` + `` – Hans Passant Oct 23 '11 at 13:44
  • Could you please show me an alternative solution. I never dealt with those things before. – the_drow Oct 23 '11 at 13:55
  • @HansPassant sorry, forgot to mention your nick. – the_drow Oct 23 '11 at 14:07
  • Use the MSDN Library for examples: http://msdn.microsoft.com/en-us/library/ms164282.aspx – Hans Passant Oct 23 '11 at 14:15

2 Answers2

2

You can utilize any methods from the System.String class in the .NET Library, including comparisons.

See http://msdn.microsoft.com/en-us/library/dd633440.aspx

Edit

And if you can't get property functions to work well enough for you, you could try the MSBuild Extension Pack. http://www.msbuildextensionpack.com/help/3.5.3.0/html/9c5401ed-6f55-089e-3918-2476c186ca66.htm

Michael Price
  • 8,088
  • 1
  • 17
  • 24
  • 1
    So you'd write `NET_4_0`? Will it work? – the_drow Oct 24 '11 at 12:42
  • @the_drow Not sure. Haven't tried Compare yet. I know that the Contain method works on a string instance though. `NET_4_0`. Not sure if this is what you want or not though. I've found the guidance on where exactly to place $ to be a bit obtuse. – Michael Price Oct 24 '11 at 17:49
  • It will work until 5.0 arrives. I need numerical comparsion of the version number. – the_drow Oct 25 '11 at 00:35
  • @the_drow If you can get the usage of `$` right in your bit above, I feel pretty confident this will work. You might want to ignore the culture and casing issues though, as you have a pretty good idea of the culture and format already. Try the simple signature instead. http://msdn.microsoft.com/en-us/library/84787k22.aspx – Michael Price Oct 25 '11 at 00:56
0

Carrying on from @MichaelPrice's answer & @HansPassant's comment...

<Choose>
  <When Condition=" '$(TargetFrameworkVersion.Substring(1,3))'&gt;'3.5' ">
    <ItemGroup>
      <DefineConstants>$(DefineConstants);NEWERTHANNET35</DefineConstants>
    </ItemGroup>
  </When>
</Choose>
CAD bloke
  • 8,578
  • 7
  • 65
  • 114