3

I'm using Rider 2021.3.3 (latest version), and when I have the latest .NET SDK on my machine (.NET 6).

Inside the .editorconfig file, I have added the following:

csharp_namespace_body = file_scoped

When I create a new project, it contains a file with a File-scoped namespace:

namespace ClassLibrary2;

public class Class1
{
}

If I change it to a block-scoped namespace and I run a cleanup, the file doesn't change but remains using the block-scoped namespace.

namespace ClassLibrary2
{
    public class Class1
    {
    }
}

Rider is configured to read settings from the .editorconfig file. Changing the rules that specifies how much blank lines are required before a single line comment, this is respected.

```csharp_blank_lines_before_single_line_comment = 1`

Any idea on what's going wrong?

Complexity
  • 5,682
  • 6
  • 41
  • 84
  • Does it work with your `.editorconfig` in Visual Studio (just to doublecheck the correctness)? And does it work with the corresponding Rider setting (_File | Settings | Editor | Code Style | C# → Syntax Style → Code Body → Namespaces_)? – mu88 Mar 29 '22 at 12:29
  • It seems it's related to a large solutions some targetting old .NET, new ones targetting .net core / net 6. – Complexity Mar 29 '22 at 13:39
  • So does it work in the newer .NET 6 settings? If so, you can try to set `latestMajor` within `csproj` of the older projects - this will enable C# 10 support and therefore file-scoped namespaces – mu88 Mar 30 '22 at 05:50
  • I know, but that;'s not what I'm looking for. I'm wondering why Rider doesn't respect the given settings in the `.editorconfig` file. – Complexity Mar 30 '22 at 06:02
  • Ah wait, do you want to happen the refactoring from block- to file-scoped namespaces __automatically__? If yes, that doesn't seem to be possible right now - at least I never found out how. We decided to set the severity for this to _Warning_ – mu88 Mar 30 '22 at 06:30
  • Have you tried running `dotnet style` command after changes to `.editorconfig`? It should apply changes to the entire project or solution (I am pretty sure it all must be in .net 6 though). – Korfu Mar 30 '22 at 18:41
  • How does that interact with Rider / ReSharper? – Complexity Mar 30 '22 at 19:09

0 Answers0