Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To global using directive refactoring

I would like to migrate my projects to .NET 6 and C# 10. As a part of this migration I would like to use global using directives.

Has Visual Studio 2022 any tool or help to do a "to global using directive" refactoring?

like image 451
g.pickardou Avatar asked Jul 26 '26 07:07

g.pickardou


2 Answers

ReSharper/Jetbrains is again one step ahead with it's 'Extract Global Using refactoring'.

If you want to know more about it https://www.jetbrains.com/help/resharper/Refactorings__Extract_Global_Using.html

like image 88
Lukáš Kmoch Avatar answered Jul 27 '26 19:07

Lukáš Kmoch


Making namespace global should render corresponding using unnecessary in other files. Remove unnecessary usings diagnostic allows you to select the scope for the fix:

enter image description here

If for some reason the diagnostic is not shown you can enable it via .editorconfig via rule code (IDE0005):

# IDE0005: Using directive is unnecessary.
dotnet_diagnostic.IDE0005.severity = suggestion
like image 31
Guru Stron Avatar answered Jul 27 '26 19:07

Guru Stron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!