How to use C# 7.2 (7.x – minor releases) in your Project

C# 7.0 and other minor releases (7.x) are loaded with many awesome features and I’ve been all those nice features recently. You can have a look here. I have seen many people facing issues with using these features. So in this quick post, I will discuss how you can leverage C# 7.x features.

Using Visual Studio 2017

To use C# 7.x features, Microsoft recommends to upgrade the IDE to Visual Studio 2017. To use C# latest minor releases C# 7.X (currently C# 7.2), this is not enough, we need to follow the below steps

  1. Right click on the project => Select Properties
  2. Select Build tab from the left pane.
  3. Go down and select Advanced button
  4. Select the Language version as

Here we can see tha the default selection is C# latest major version (default) which means 7.0. We also have the option to select specific versions like 7.0/7.1 but for 7.2, we need to select C# latest minor version (latest).

Using Visual Studio 2015

As mentioned above that Microsoft recommends to use Visual Studio 2017 for C# 7.x features but as these features are implemented by compiler so as long as your build is pointing to correct version of CSC, you can build the new features. However, Visual Studio 2015 may not like it as it doesn’t understand the new features and you may not get intellisense or any other IDE support.

To use C# 7.X in Visual Studio 2015, install the following nuget package

Microsoft.Net.Compilers

Once, you install this package, you should be able to use the latest language feature in VS 2015. However you might red   squiggly in the editor as

Here we can see that even the VS2015 editor is complaining but it is getting built.

Using System.ValueTuple

ValueTuple is not available by default as part of C# 7.0, we need to install following nuget package

System.ValueTuple

Hope you like the post and able to use the C# latest features.

Cheers,
Brij

Advertisement

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 )

Facebook photo

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

Connecting to %s