CSharply 1.40.0
See the version list below for details.
dotnet tool install --global CSharply --version 1.40.0
dotnet new tool-manifest
dotnet tool install --local CSharply --version 1.40.0
#tool dotnet:?package=CSharply&version=1.40.0
nuke :add-package CSharply --version 1.40.0
CSharply
An opinionated tool that organizes C# files according to best practices. Available as a CLI tool, web API, and VS Code extension.
Features
- 🎯 Automatic Code Organization: Organizes all members and using statements
- 🔧 Multiple Interfaces: CLI, Web API, and VS Code extension
- ⚡ Fast Performance: Built with Roslyn for accurate C# parsing
- 🌐 Cross-Platform: Works on Windows, macOS, and Linux
- 📁 Batch Processing: Organize entire directories or single files
- 🔄 Real-time Processing: Web server for fast operations without startup costs per request
Installation
CLI Tool (Global)
dotnet tool install --global CSharply
VS Code Extension
Install from the Visual Studio Marketplace or search for "CSharply" in VS Code extensions.
Usage
Command Line Interface
Organize a single file
csharply organize MyClass.cs
Organize an entire directory
csharply organize ./src
Get help
csharply --help
csharply organize --help
Web Server Mode
Start a web server to organize code via HTTP API:
csharply serve
csharply serve --port 8149
API Endpoints
GET /health- Health checkPOST /organize- Organize C# code (plain text body)
Example API Usage
# Organize code via plain text
curl -X POST http://localhost:8149/organize \
-H "Content-Type: text/plain" \
-d "using System.Linq; using System; class Test { }"
VS Code Extension
Ctrl+Shift+P, then CSharply: Organize C# file or CSharply: Organize all C# files in workspace folders
What Gets Organized
CSharply organizes your C# code according to Microsoft's coding conventions:
Using Statements
- Sorts alphabetically
- Groups System namespaces first
Rules
Member Order:
- Namespaces
- Interfaces
- Fields
- Properties
- Constructors
- Methods
- Nested types
- Enums
Access Modifier Order:
- public
- internal
- protected
- private
Note: If the file contains pre-processor directives such as #if or #region, the file will not be organized.
Example
Before:
using System.Collections.Generic;
using System.Linq;
using System;
namespace MyProject
{
public class Example
{
public void DoSomething1() { }
private string _field1;
public void DoSomething2() { }
public Example() { }
public string Property { get; set; }
private string _field2;
}
}
After:
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyProject
{
public class Example
{
private string _field1;
private string _field2;
public Example() { }
public string Property { get; set; }
public void DoSomething1() { }
public void DoSomething2() { }
}
}
Ignoring Files
CSharply supports a .csharplyignore file to exclude specific files and directories from organization. This is useful for:
- Generated code files
- Third-party libraries
- Legacy code that shouldn't be modified
- Files with custom formatting requirements
Creating a .csharplyignore File
Create a .csharplyignore file in your project root or any directory you want to organize. The file uses gitignore-style patterns:
# Ignore all generated files
**/Generated/
**/*.Designer.cs
**/*.g.cs
# Ignore specific files
Models/LegacyModel.cs
Controllers/ThirdPartyController.cs
# Ignore by pattern
**/*Template*.cs
**/Migrations/**/*.cs
# Ignore entire directories
bin/
obj/
packages/
Pattern Syntax
The .csharplyignore file supports the same globbing patterns as .gitignore:
| Pattern | Description | Example |
|---|---|---|
*.cs |
Match any .cs file | Generated.cs, Model.cs |
**/Generated/ |
Match Generated directory anywhere | src/Generated/, test/Generated/ |
Models/*.cs |
Match .cs files in Models directory | Models/User.cs |
**/*.Designer.cs |
Match Designer.cs files anywhere | Form1.Designer.cs |
!Important.cs |
Negation - don't ignore this file | Override previous ignore rules |
How It Works
- CSharply looks for
.csharplyignorefiles starting from the target directory - It walks up the directory tree to find additional ignore files
- Patterns are applied in order, with more specific files taking precedence
- Files matching any pattern are skipped during organization
Examples
Basic Project Structure
MyProject/
├── .csharplyignore # Root ignore file
├── src/
│ ├── .csharplyignore # Source-specific ignores
│ ├── Controllers/
│ ├── Models/
│ └── Generated/ # Ignored directory
├── tests/
└── bin/ # Ignored directory
Sample .csharplyignore for ASP.NET Core
# Build outputs
bin/
obj/
publish/
# Generated files
**/*.Designer.cs
**/*.g.cs
**/Migrations/*.cs
# Third-party code
**/ThirdParty/
**/External/
Sample .csharplyignore for WinForms/WPF
# Designer files
**/*.Designer.cs
**/*.g.cs
# Build outputs
bin/
obj/
# Legacy code
**/Legacy/
**/Old/
Verbose Output
Use the --verbose flag to see which files are being ignored:
csharply organize ./src --verbose
# Output will show:
# skipped : src/Generated/Model.cs
# organized : src/Controllers/UserController.cs
Command Line Options
csharply organize [options] <path>
Options:
--simulate, -s Simulate changes without writing files
--verbose, -v Enable verbose output
--help, -h Show help information
csharply server [options]
Options:
--port <port> Port to listen on (default: 8149)
--help, -h Show help information
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.42.0 | 152 | 1/29/2026 |
| 1.41.0 | 109 | 1/29/2026 |
| 1.40.0 | 116 | 1/29/2026 |
| 1.36.0 | 114 | 1/29/2026 |
| 1.35.0 | 112 | 1/29/2026 |
| 1.34.0 | 112 | 1/29/2026 |
| 1.33.0 | 119 | 1/29/2026 |
| 1.32.0 | 118 | 1/29/2026 |
| 1.31.0 | 109 | 1/28/2026 |
| 1.26.0 | 116 | 1/28/2026 |
| 1.25.0 | 113 | 1/28/2026 |
| 1.24.0 | 116 | 1/28/2026 |
| 1.23.0 | 107 | 1/28/2026 |
| 1.22.0 | 114 | 1/28/2026 |
| 1.21.0 | 111 | 1/28/2026 |
| 1.20.0 | 178 | 11/7/2025 |
| 1.19.0 | 166 | 11/7/2025 |
| 1.18.0 | 236 | 10/30/2025 |
| 1.17.0 | 199 | 10/30/2025 |
| 1.16.0 | 220 | 10/30/2025 |