Is there a consensus within the C# development community on the .cs filename in which global using statements are declared?
I was going to adopt the filename GlobalUsings.cs but then found that a hidden file called MyProject.GlobalUsings.g.cs is created behind the scenes by the VS2022 toolchain. This is to support the related new C# 10 feature called Implicit global using directives.
Blazor has supported a similar feature for .razor files and the Blazor solution template automatically creates a file called _Imports.razor. That name is derived from the Razor syntax to declare a using reference.
Usings.cs
or maybe GlobalUsings.cs
.
There are actually 2 new features. They seem really simple at first, but the more you read about it, the more complicated it becomes.
global
in front of any using directive in any file to make it global in the project.<PropertyGroup><ImplicitUsings>enable</ImplicitUsings>...
Implicit usings is enabled by default on new .NET 6 projects, so it sounds like the convention is:
GlobalUsings.cs
. It's self-documenting.In fact, this naming is recommended by the Welcome to C# 10 Blog. I highly recommend reading it; it was really helpful to me.
This seems to keep changing. .NET 6 project templates are now including a Usings.cs
file.