I would like to get the .Net version number in C# code, so in the .csproj file, I added the following line:
<DefineConstants Condition=" $(TargetFrameworkVersion.Replace('v', '')) >= 3.5 ">$(DefineConstants);NET35_ABOVE</DefineConstants>
Then in the C# code I can use “#if NET35_ABOVE” to check if the current .Net version is newer than 3.5. The line above works OK in MSBuild 4.0, but MSBuild 3.5 doesn’t recognize the “Replace” function. If I were to dynamically check .Net version in a similar fashion, how can I do it in MSBuild 3.5?
Your example seems to work just fine in VS2010.
Here’s what I tried:
Edit:
But since you’re using VS2008 you can use the the and do something like this