How do I disable C# 6 Support in Visual Studio 2015?

C#Visual StudioC# 5.0Visual Studio-2015C# 6.0

C# Problem Overview


Background

We have a project that we're developing in VS 2015 with C#6 enabled that occasionally needs to be opened by developers using VS 2013 without C#6.

We have no intention to use C# 6 within this particular solution (as much as I'd like to).

Problem

Visual Studio and ReSharper suggest helpful C# 6 language constructs that render the solution inoperable in earlier versions of Visual Studio without C#6 support.

I've disabled the ReSharper C#6 support but I can't seem to disable / limit C# features across the whole solution.

Question

How do I limit C# to C#5 capabilities within a solution or within Visual Studio 2015?

C# Solutions


Solution 1 - C#

You can set the language feature for each project separately by going to Properties => Build tab => Advanced button => Language Version and set your preferred version.

You should realize that it will still use the new "C# 6.0" .Net Compiler Platform (codenamed Roslyn). However, that compiler will imitate the behavior of older compilers and will limit you to features only available on that specific language version.


I don't think that there's a solution-wide setting available.

Solution 2 - C#

add below in .sln.DotSettings should disable it on solution level

<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp50</s:String>

Or if you don't have a .sln.DotSettings file:

  1. If your solution file is called Apple.sln, create a file beside it called Apple.sln.DotSettings.

  2. Give it the following contents:

     <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
         <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp50</s:String>
     </wpf:ResourceDictionary>
    
  3. Close and reopen the solution, Resharper should only warn you about C#5 things.

  4. Don't forget to remove this when you eventually start using C#6 features! :)

Solution 3 - C#

This tool I wrote might help you if you have many projects that you need to set LangVersion for.

Solution 4 - C#

You can set the language feature for all the solutions/csproj with the MSBuildUserExtensionsPath.

Search the value of the $(MSBuildUserExtensionsPath), it should be something like C:\Users\$(User)\AppData\Local\Microsoft\MSBuild

Then edit the file Force.LangVersion.ImportBefore.props in the folder $(MSBuildUserExtensionsPath)\14.0\Imports\Microsoft.Common.Props\ImportBefore with :

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <LangVersion>5</LangVersion>
  </PropertyGroup>
</Project>

Solution 5 - C#

Steps have already been written above, just adding a screenshot further of my VS2015:

Properties of project >> Build >> Advanced >> Language version

enter image description here

I set that to C# 5.0.

Solution 6 - C#

Right click on Project in Project Explorer and select Properties.

When the Properties tab opens select Build and the click the Advance button in bottom right.

There is drop-down box called Language Version. Change the select to "C# 5.0"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSeanKilleenView Question on Stackoverflow
Solution 1 - C#i3arnonView Answer on Stackoverflow
Solution 2 - C#harishrView Answer on Stackoverflow
Solution 3 - C#khellangView Answer on Stackoverflow
Solution 4 - C#fhussonView Answer on Stackoverflow
Solution 5 - C#RaghavView Answer on Stackoverflow
Solution 6 - C#NicknowView Answer on Stackoverflow