A way to get VS2015 to check for earlier C # syntax to support VS2013 compatibility

The specific problem that I encountered is that VS2015 allows you to use the new C # syntax, for example. public string MyProperty => _myProperty; when targeting a project of the .NET 4.0 platform, and then others opening the project in VS2013 get compiler errors.

Is there a way to configure VS2015 to warn or about errors in features specific to C # 6? Or said another way, can I tell VS2015 which version of C # I want to compile?

+6
source share
2 answers

Yes, but it needs to be done for each project. This is an option available in the Build menu of project properties. Click "Advanced" in the lower right corner, then select the desired language version.

enter image description here

Note. There is a VS2015 bug (which was fixed in Update 1) that causes false negatives for automatic get-only properties. For best results, make sure you have installed the latest update.

+5
source

In order to agree on the accepted answer, to quickly implement this in 100 projects and get all the configurations, and not just the specific configuration, I massively edited the csproj files and inserted the <LangVersion>5</LangVersion> node as the first child inside the first naked, unconditional <PropertyGroup> node:

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <LangVersion>5</LangVersion> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 
+1
source

All Articles