Skip to content

A global .NET Core tool for ordering alphabetically, length, the references of packages or imports in your .NET Core and .NET Standard projects.

License

Notifications You must be signed in to change notification settings

ramosisw/dotnet-sort

Repository files navigation

dotnet-sort

License NuGet Version NuGet Download

A global .NET Core tool for ordering alphabetically, length, the references of packages or imports in your .NET Core and .NET Standard projects.

Installation

dotnet tool install --global dotnet-sort

Usage

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

Examples

Command to sort references -a=r alphabetically ascending -s=a

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>

Command to sort imports -a=i by length descendently -s=ld

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;

Command to sort imports -a=i by length ascending -s=la

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;

About

A global .NET Core tool for ordering alphabetically, length, the references of packages or imports in your .NET Core and .NET Standard projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published