How to find candidates for implicit usings in C#

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:

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:

<Project Sdk="Microsoft.NET.Sdk">
    <Using Include="FluentAssertions" />
    <Using Include="Xunit" />

Leave a Reply

Your email address will not be published. Required fields are marked *