Implicit using is a feature which comes with C# 10. The question is how to find candidates for implicit usings in some C# project. For this task following PowerShell snippet can be used:
1 2 3 4 5 | Get-ChildItem *.cs -Exclude *assembly* -Recurse ` | Get-Content ` | Select-String using ` | Group-Object ` | Sort-Object -Property Count -Descending |
After running this command in folder with some C# files you can discover repeating usings, for example that in unit tests are repeating using of FluentAssertions and Xunit which can be added into .csproj file as implicit usings:
1 2 3 4 5 6 7 8 9 10 | < Project Sdk = "Microsoft.NET.Sdk" > < PropertyGroup > < TargetFramework >net6.0</ TargetFramework > < ImplicitUsings >enable</ ImplicitUsings > </ PropertyGroup > < ItemGroup > < Using Include = "FluentAssertions" /> < Using Include = "Xunit" /> </ ItemGroup > </ Project > |