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

1

13

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?

Holiday answered 7/8, 2015 at 12:32 Comment(1)
I am not sure, but: If all your colleagues used Visual Studio 2015, you could perhaps set up some custom Roslyn-based code analysis that warns you when you use a feature that is not supported in earlier versions. But since they have Visual Studio 2013 (which is not yet fully based on Roslyn AFAIK), this is likely not an option.Jessamyn
R
22

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.
Rebozo answered 7/8, 2015 at 12:32 Comment(1)
Don't make the same mistake i did by forgeting to check the Build Configuration (Debug, Release, All Configurations), otherwise you might find a surprise later... @Petrichor: Thank you for fixing my problem.Holiday

© 2022 - 2024 — McMap. All rights reserved.