Resharper insists on reformatting namespace to C# 10 syntax on my machine with trailing ' ;'

On my machine I updated VisualStudio 2022 version 17.3.5  and Resharper version 2022.2.3,  the latest versions as of 29/09/2022.

We are working on C#  .NET.Framework projects which I understood should be compiled with C# version 7.3 although that is not the case.

When I run Resharper 'Cleanup code' Ctrl-EC on my machine all the namespaces are changed to C# 10 syntax with a trailing ' ;'
namespace name
namespace name ;

The rest of the file is left unchanged and so it is not even reaping the  benefit of removing 1 level of indentation though out the file which to my mind is the only point of this language change. Even if we wanted this change, why would we want the trailing ' ;' I am unaware of any programmer who would want a space before a semicolon and that has been the case in the whole of my 39 years experience across pascal C, C++ and C#, Javascript, and Java.

My colleagues, with exactly the same name.Sln.DotSettings, do not see this. It leaves the namespace unchanged, which I found puzzling.

I tried adding Directory.Build.props as documented on
<?xml version="1.0"?>

However, several files in our projects are already using C# 9.0 features. So the solution would not build. So I set it to 9.0 and tried re-running.

Then I discovered why Resharper had upgraded my local project to version 10. It was  because I left 1 public qualifier in an interface that I had created from the class for IOC purposes, which is a version 10 feature which I was unintentionally using. I fixed this.

I ran Code cleanup again with version 9.0  in Directory.Build.props and it did not revert the namespaces to the version 9.0 syntax.

So the buid fails at this point with the version 10 syntax namespaces resharper had created and kept in the new configuration.

It would be nice if Resharper could downgrade changes it has made when the language version is decremented.

I changed all the files back to version 9.0 syntax namespaces manually and that built fine.

Running 'Code cleanup' again and it retained the the version 9.0 syntax as expected.

It would be nice to have an option to select which version of the language, in this case C#, you are aiming to format for in the UI options. I failed to find any mention of such  a button in the product or on the web. The same has been suggested to the VisualStudio team  for Compilation files.
Similar there you need to edit the project file.

We want to change it easily in the UI. Rather than have to trawl the web to find out about Directory.Build.props and use text editors on files that are renowned for typos.

Lastly but not least could we have an option to get rid of that space before the semicolon and could that option be the default, which apparently it is not.

Please sign in to leave a comment.