C# : Enabling C# 7.1 on Visual Studio 2015 / 2013

The C# compiler supports C# 7.1 starting with Visual Studio 2017 version 15.3, or the .NET Core SDK 2.0.

This is what Microsoft says in their documentations. But still if you kind of not really willing to go to Visual Studio 2017 and using Visual Studio 2015 or even 2013, its not a big deal but you have to add some Nuget packages + edit the .csproj file

Step 1

Create a new C# project and install Microsoft.Net.Compilers v 2.4.0
Install-Package Microsoft.Net.Compilers -Version 2.4.0

Step 2

Edit the .csproj file to have

<LangVersion>Latest</LangVersion>

under

<PropertyGroup>

Now we are ready to test the code, so just modify the Program.cs like below

class Program
{
   static async Task Main(string[] args)
   {
      await Task.Delay(5000);
      Console.Beep();
   }
}

Step Next

Inferred tuple element names is a new functionality in C# 7.1 but you can’t just use Tuples unless you have System.ValueTuple nuget package installed, so install it using Install-Package System.ValueTuple -Version 4.4.0
Now, you should be able to use,

class Program
{
	static async Task Main(string[] args)
	{
		int count = 5;
		string label = "Colors used in the map";
		var pair = (count, label);
		Console.Write(pair);
		Console.ReadKey();
	}
}

VS2013C71

So, like this you have to install the needed nuget packages.

Happy Coding.

4 thoughts on “C# : Enabling C# 7.1 on Visual Studio 2015 / 2013

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s