List of C# 6 settings to provide C# 5 compatible changes

Hi

Is there a list of new R# settings that cater for C#6 settings?  I need to make sure that whatever fixes are applied by R# in VS 2015 stays compatible with VS 2013 and therefore C#5.  Currently it is removing private setters etc as part of Code Cleanup and this introduces a breaking change for VS 2013 users.

9 comments

Did you try setting the "C# Language Level" in the properties window for the project? If you set that to "C# 5.0", it should prevent R# from suggesting C# 6 features.

0

According to this link:

https://www.jetbrains.com/resharper/help/ReSharper_by_Language__CSharp.html


ReSharper should by default automatically detect C# version based on the project settings. This does not seem to work. I have one big solution with projects targeting .NET 4 and another big solution with projects targeting .NET 4.5. In both cases, ReSharper 9/VS2015 displays C# 6 suggestions by default.

Do I really need to change "C# Language Level" on all my projects to get this to work? If so, could I at least modify the solution-wide file (*.sln.DotSettings)?

1

Most of the new C# 6 features are just syntactic sugar. So long as you use VS2015 to compile the code, and you've set the correct target framework, the compiled program will work whether the PC it's deployed to has .NET 4.0, 4.5 or 4.6 installed.

It makes sense to suggest using these new features if you're using VS2015. You only need to avoid them if you're sharing your project with developers who are still using VS2013 or earlier.

0

And/or if you're using a build server that doesn't support C# 6.  I also would prefer a global "language version" setting for this reason.  

I assume by your dismisal of the requirement you are implying that no such setting exists?

0

There are a couple of ways to specify not to use C#6.0 on a build server where you run R# Commad Line Tools to analyze your solution:

  1) specify "toolset" parameter for inspectcode.exe. It will let R# CLT know about decired MSBuild toolset version - "4.0" (VS2010 or VS2012), "12.0" (VS2013) or "14.0" (VS2015). So if you select any value apart from "14.0" - there won't be any C#6.0 related inspections. So, the command line should be:

  inspectcode.exe {solution name}.sln /toolset=12.0


  2) specify "C#5.0" value for R# "C# Language Level" property for whole solution in setting file you use to run inspectcode.exe. Add the following line to the file:

  <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp50</s:String>


  By the way, you may specify needed C# version for whole solution in ReSharper following the way mentioned in the second item.

Hope it helps.

Thanks!

1

Thank you for the information, I will keep it in mind if I need it in the future.  However, I think you misunderstood my intent: I mean to reply to Richard Deeming's dismissal of the OP's requirement.  He stated:

> You only need to avoid them if you're sharing your project with developers who are still using VS2013 or earlier.

And when I replied:

> And/or if you're using a build server that doesn't support C# 6.  I also would prefer a global "language version" setting for this reason.

I was indicating that you would also want the OP's requirement (R# should only perform C# 5 compatible refactoring) if your build server did not support C# 6.  This is the case I find myself in.  My build server does not support C# 6, and as such I do not want R# in my VS2015 to perform refactorings using C# 6 syntax.  I do not require settings to make my build server not use C# 6 - it already doesn't.

0

I wasn't dismissing the OP's requirement - I was just pointing out that you can use a lot of C#6 features if you're using VS2015, even if you're targeting earlier framework versions.

And I'm not a member of JetBrains staff, so I don't know what internal settings there are. :)

0

RichardD wrote:

I wasn't dismissing the OP's requirement - I was just pointing out that you can use a lot of C#6 features if you're using VS2015, even if you're targeting earlier framework versions.

And I'm not a member of JetBrains staff, so I don't know what internal settings there are. :)

And you still haven't understood the problem.

The build server doesn't have the requisite compiler, so the build fails if there is any v6 syntax be that C# or VB.

Having to change a setting in 50 some projects is not conducive to good mental health.

0

Yeah same problem yada yada. WTH ReSharper? You've been really good about this in the past. Now in VS2015 EVERYTHING is C#6.

0

Please sign in to leave a comment.