Skip to content

Instantly share code, notes, and snippets.

@nordinrahman
Created November 20, 2016 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nordinrahman/24644be1001cab67c9961ed046bf5d6f to your computer and use it in GitHub Desktop.
Save nordinrahman/24644be1001cab67c9961ed046bf5d6f to your computer and use it in GitHub Desktop.
PropertyGroup element to define .NET constants
<PropertyGroup>
<NetFrameworkVersionNum>$(TargetFrameworkVersion.Replace("v", "").Replace(".", ""))</NetFrameworkVersionNum>
<!--Add an extra 0 if the version number is 40 or 45 so it can be compared to 401-->
<NetFrameworkVersionNum Condition="$(NetFrameworkVersionNum.Length) &lt; 3">$(TargetFrameworkVersion.Replace("v", "").Replace(".", ""))0</NetFrameworkVersionNum>
<!--Don't define your own NET constants - this file will do it for you-->
<Error Condition=" $(DefineConstants.Contains('NET'))">Don't define your own NET constants</Error>
<!--Create a version to use with constants NET40, NET401 etc.-->
<NetFrameworkVersion Condition=" !$(DefineConstants.Contains(';NET')) ">$(TargetFrameworkVersion.Replace("v", "NET").Replace(".", ""))</NetFrameworkVersion>
<DefineConstants Condition=" !$(DefineConstants.Contains(';NET')) ">$(DefineConstants);$(NetFrameworkVersion)</DefineConstants>
<!--Define the OR_GREATER constants-->
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 350">$(DefineConstants);NET35_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 400">$(DefineConstants);NET40_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 450">$(DefineConstants);NET45_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 451">$(DefineConstants);NET451_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 452">$(DefineConstants);NET452_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 460">$(DefineConstants);NET46_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 461">$(DefineConstants);NET461_OR_GREATER</DefineConstants>
<DefineConstants Condition="$(NetFrameworkVersionNum) &gt;= 462">$(DefineConstants);NET462_OR_GREATER</DefineConstants>
</PropertyGroup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment