A global .NET Core tool for ordering alphabetically, length, the references of packages or imports in your .NET Core and .NET Standard projects.
dotnet tool install --global dotnet-sort
Usage:
dotnet-sort [options]
Options:
-h, --help Show command line help.
-p, --path Path where found the *.csproj or *.cs files (defaults to the current directory)
-a <APPLY> Apply to references or imports.
Examples:
Sorting references and imports on *.cs (default): -a=ri
Sorting only references on *.csproj: -a=r
Sorting only imports on *.cs: -a=i
-s <MODE> Sort by length/alphabetically
Examples:
alphabetically ascending (default): -s=a
alphabetically descendently: -s=ad
length ascending: -s=l
length descendently: -s=ld
dotnet-sort --path=Project.csproj -a=r -s=a
Project.csproj
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Grpc" Version="1.19.0" />
<PackageReference Include="Google.Protobuf" Version="3.7.0" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.7.0" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.7.0" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.7.0" />
<PackageReference Include="Grpc" Version="1.19.0" />
</ItemGroup>
</Project>
dotnet-sort --path=Code.cs -a=i -s=ld
Code.cs
using System.Text.RegularExpressions;
using System.Linq;
using System;
using System.IO;
using System.Text;
using System.Xml.XPath;
using System.Text.RegularExpressions;
using System.Xml.XPath;
using System.Text;
using System.Linq;
using System.IO;
using System;
dotnet-sort --path=Code.cs -a=i -s=ld
Code.cs
using System.Text.RegularExpressions;
using System.Linq;
using System;
using System.IO;
using System.Text;
using System.Xml.XPath;
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Xml.XPath;
using System.Text.RegularExpressions;