New feature to enable C# 6 / VB 14

Web Development Tools Microsoft

The model to leverage updated versions of C# or VB in web apps has changed over the past few years. In the past to leverage a new version of C# or VB you would get the runtime and build tools by installing the .NET Framework. With Visual Studio 2015 and the latest version of MSBuild this is no longer needed. You can decide which applications leverage C# 6/VB 14 by adding a NuGet package, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, to your web projects. When you add this NuGet package to your web applications then you can start using C# 6/VB 14 in both the code behind as well as Views.

 

In Visual Studio 2015 Update 1 we have included a new feature to simplify this. When you have a solution open which has at least one web project which is targetting .NET 4.5+ and does not have the DotNetCompilerPlatform NuGet package in the Project menu you’ll see a new option, Enable C# 6 / VB 14 appear.

project-menu

 

When you select the Enable C# 6 / VB 14 menu option a dialog will appear showing all web projects which can be updated to support C# 6 / VB 14. In this case the solution that I have opened has two web projects which can be updated to support C# 6. When the dialog appears I can see both projects and can select the ones that I want to be updated for C# 6.

project-selection

In this case I’ll just select WebApplication1 to be updated. After selecting to enable C# 6, the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package is installed into the project. Now I can use C# 6 in both the code behind files as well as the views.

Because the support to leverage C# 6 / VB 14 is shipped as a part of your project, when you publish there will be some additional files that will get published. If you are not planning to leverage C# 6 / VB 14 then it’s recommended to not install this NuGet package as it will just slow down your deployment speeds.

 

Thanks,
Sayed Ibrahim Hashimi

0 comments

Discussion is closed.

Feedback usabilla icon