1

Is it possible to define a compile time constant that would say if code is compiled by C# 5 or C# 6? For example:

<DefineConstants Condition=" '$(???LanguageVersion???)' != 'v6.0' ">
     NOT_RUNNING_ON_6
</DefineConstants>
Jan Matousek
  • 956
  • 3
  • 13
  • 15
  • I'll leave it to you to add the missing `>` on the first line –  Feb 03 '16 at 11:30
  • Related: http://stackoverflow.com/q/32987410/109702 – slugster Feb 03 '16 at 11:35
  • Check out [this answer to a similar question to yours](http://stackoverflow.com/questions/2923210/conditional-compilation-and-framework-targets?lq=1), utilizing build configurations. – RaidenF Feb 03 '16 at 11:38
  • It is similar to detecting .NET version, but from the answer bellow the difference is that it's not possible in a simple way. – Jan Matousek Feb 03 '16 at 11:42

1 Answers1

1

The constants defined in the project file are all set by MSBuild. Which doesn't know the compiler version. It also only delegates all those properties to the Csc task. Since the compiler doesn't set constants based on the version, you simply cannot do that.

You could use a custom build process wrapper that determines the compiler version and changes the project file accordingly, though.

Joey
  • 344,408
  • 85
  • 689
  • 683