Turn off C# 6.0 features in VS2015/Resharper 9 when using NET 4.5

If you are working on a NET 4.5 project using VS2015 + ReSharper 9, you will find that (by default), VS2015 and ReSharper will allow you (and even encourage you) to use the new C# 6.0 features within your source code.

In some cases, ReSharper will recommend some C# 6.0 features as a way to improve your code.

For example, in my example C# 4.5 code I have the following line:
var messageOutput = string.Format(“Tax balance: {0} [{1}]”, status.Balance, status.Status);

ReSharper recommends me to change it to:
var messageOutput1 = $”Tax balance: {status.Balance} [{status.Status}]”;

If I complete this “recommended” change, VS2015 will compile my updated code successfully (on my local machine). [No errors are shown during my local machine build].

When I commit this change, the build server will try to compile the code using NET 4.5 which does NOT support this new C# 6.0 feature – and I will get a build failure message. I will now need to “fix” my code by reversing my change and committing my change.

Fixing this issue by configuration

There are simple steps that you need to take to avoid this issue altogether.
The following steps will:

  • force your VS2015 to compile your 4.5 project using C# 5.0, and
  • prevent ReSharper from suggesting C# 6.0 features as code improvements

Step #1

Click on a project in your solution. Look for the panel named “Properties”
(usually shown below the Solution Explorer).

2015-12-01_15-05-18

Make sure to change the setting of the C# Language Level to: C# 5.0

(You must complete this change for every project in your solution.
There is no solution-wide setting for the language level.)

Step #2

Right-click on a project in your solution and select the option “Properties”;
Go to the “Build” tab and click on the “Advanced” button near the bottom right of this panel.

2015-12-01_15-23-35

Change the setting for Language version to: C# 5.0 (see below)

2015-12-01_15-26-10

Result:

After you make the 2 changes shown above, then you will see that:

  • VS2015 will fail to compile when you add C# 6.0 features to the source code
  • ReSharper will stop suggesting changes that involve C# 6.0 features

I hope you find this post useful to you in avoiding build issues when using the new VS2015 + ReSharper 9. If you have any comments or questions, please email me and I will try to answer them right away.

Leave a Reply

Skip to toolbar