C# 6.0 Features Not Working with Visual Studio 2015

C# 6.0 Features Not Working with Visual Studio 2015

This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package

CodeDOM Providers for .NET Compiler...

Replacement CodeDOM providers that use the new .NET Compiler Platform ("Roslyn") compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as well as improving the compilation performance of these systems.

PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/

No C# 6.0 in Visual Studio 2015 CTP?

There is a bug in the CTP where the LangVersion switch is case sensitive. Try using experimental instead.

C# 6 in Visual Studio 2015 - langversion 'experimental' is not supported

Visual Studio 2015 comes with C# 6.0. You don't need any extra settings, that was true in older versions.

You should also note that Parameterless Struct Constructors didn't make it to C# 6.0.

This can be seen with a TryRoslyn example (which operates on the latest version of Roslyn).

This struct:

public struct Point
{
public int x;
public int y;

public Point()
{
this.x = 0;
this.y = 0;
}

public Point(int x, int y)
{
this.x = x;
this.y = y;
}
}

Gives this warning:

Error CS0568: Structs cannot contain explicit parameterless constructors

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

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.

VS 2015 will not build my project as C# 6.0

C# 6.0 features are not automatically available in MVC5 projects (in Razor), you have two options:

  • Update to MVC 6 beta
  • Install CodeDOM Providers for .NET Compiler, see details here

Why does VS2015 allow C# 6.0 functions for .Net 4.5.2 applications?

C# 6 is a new version of language C#, it has nothing to do with .NET Framework version. So you can use C# 6 even with old version's of .NET. Roslyn compiler is a new compiler that is shipped with VS2015, but could be installed on older versions of VS as standalone. So basically Roslyn compiles the new features for you, regardless the framework version you are using.

Target .Net 4.5 in VS2015 but I am allowed to use C# 6 features?

C# 6 features such as string interpolation are compiler features, not runtime (CLR) features. Therefore, you can use them regardless of what version of .NET you are building against, as long as your compiler supports C# 6.

In Visual Studio 2015 you can control which version of the language you are targeting in Properties => Build tab => Advanced button => Language Version



Related Topics



Leave a reply



Submit