An opinionated tool that organizes C# files according to best practices. Available as a CLI tool, web API, and VS Code extension.
- 🎯 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
dotnet tool install --global CSharplyInstall from the Visual Studio Marketplace or search for "CSharply" in VS Code extensions.
csharply organize MyClass.cscsharply organize ./srccsharply --help
csharply organize --helpStart a web server to organize code via HTTP API:
csharply serve
csharply serve --port 8149GET /health- Health checkPOST /organize- Organize C# code (plain text body)
# 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 { }"Ctrl+Shift+P, then CSharply: Organize C# file or CSharply: Organize all C# files in workspace folders
CSharply organizes your C# code according to Microsoft's coding conventions:
- Sorts alphabetically
- Groups System namespaces first
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.
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() { }
}
}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
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/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 |
- 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
MyProject/
├── .csharplyignore # Root ignore file
├── src/
│ ├── .csharplyignore # Source-specific ignores
│ ├── Controllers/
│ ├── Models/
│ └── Generated/ # Ignored directory
├── tests/
└── bin/ # Ignored directory
# Build outputs
bin/
obj/
publish/
# Generated files
**/*.Designer.cs
**/*.g.cs
**/Migrations/*.cs
# Third-party code
**/ThirdParty/
**/External/# Designer files
**/*.Designer.cs
**/*.g.cs
# Build outputs
bin/
obj/
# Legacy code
**/Legacy/
**/Old/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.cscsharply 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