Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the .NET Version for VisualStudio2015 (Code)

Some people in our team are using VisualStudio 2015 while the rest is still using 2013 (both with ReSharper 9.1). The Target Framework in the project properties is set to .NET Framework 4.5.1.

My Problem: I can still use code like

public int X() => x;

which is a .NET 4.6 feature. When I build the project, it also runs (I guess because it's more or less syntactical sugar, so the compiler makes code that doesn't require .NET 4.6). My colleagues however are not very amused, when they check out my changes in Visual Studio 2013 ;-)

Is it possible to get warnings / compile errors in Visual Studio 2015 for using .NET 4.6 features?

like image 239
TheWho Avatar asked Aug 07 '15 12:08

TheWho


1 Answers

That is an expression-bodied member and it is a new language feature introduced in C# 6.0.

The language and the framework/runtime libraries are versioned separately.

What you really want to do is change the language version.

  1. In the Solution Explorer, right-click on the project name, then click the menu item entitled Properties
  2. Click on the Build tab, and then the Advanced button. A window should appear.
  3. From the Language Version dropdown, choose C# 5.0.
  4. Hit the OK button, then re-build.
like image 107
Alex Booker Avatar answered Sep 21 '22 03:09

Alex Booker