A specific problem I'm running into is that VS2015 allows you to use newer C# syntax, e.g. public string MyProperty => _myProperty;
when targeting a .NET 4.0 framework project and then others opening the project in VS2013 get compiler errors.
Is there a way to configure VS2015 so that it warns or errors on features specific to C# 6? Or said another way, can I tell VS2015 which version of C# I'd like to compile against?
Yes, but this needs to be done on a per-project basis. It's an option available in the Build menu of the project properties. Click "Advanced" in the bottom right, then select the language version you want.
Note: There is a VS2015 bug (which has been fixed in Update 1) that causes false negatives on get-only auto-properties. To get the best results, make sure you have installed the latest update.
To piggyback on the accepted answer, to quickly implement this in 100's of projects, and to get all configurations and not just a specific configuration, I mass edited the csproj
files and inserted a <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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With