Enforcing Consistent .NET Code Style in Rider Using Shared Code Style and Code Cleanup
Use JetBrains Rider’s shared Code Style and Code Cleanup to enforce deterministic formatting and naming across a .NET team without external tools. Follow this step‑by‑step guide to import settings, enable analysis, run cleanup, and verify consistency.
12 Sept 2025, 21:40 UTC

Desired Outcome
Make every commit in the repository look the same: indentation, line breaks, naming conventions, and using‑directive order are automatically applied by JetBrains Rider. The goal is to eliminate style noise in code reviews and give developers a single source of truth for formatting.
Prerequisites
- All team members have Rider 2025.x or newer installed and are running the same major version to avoid subtle rule changes.
- The solution uses SDK‑style .NET projects (SDK‑style .csproj) so that
.editorconfigis respected. - A shared settings repository exists: either a
.editorconfigfile checked into source control or a Ridersettings.zipexported from one developer and committed. - Team members have write access to the solution and Git history to commit the cleanup changes.
Focused Procedure
- Export the current team settings (once). In Rider, choose
File | Manage IDE Settings | Export Settings…. SelectCode Style,Code Cleanup, andInspection Settings. Save the resultingsettings.zipinto the repository root.Tip: Keep a backup of personal settings before import; Rider will overwrite local preferences.
- Import the shared settings on every machine. Open the solution, go to
File | Manage IDE Settings | Import Settings…, and point to thesettings.zipin the repo. Verify the dialog shows thatCode StyleandCode Cleanupare selected.After import, Rider will apply the rules automatically on the next project load.
- Enable Solution‑wide Analysis. In the
Inspection Settingspanel, checkAnalyze solution on loadandShow inspection results in the editor. This ensures the IDE flags any style violations immediately.Large solutions may take a few minutes; Rider shows progress in the bottom status bar.
- Create a Code Cleanup profile. Go to
Tools | Code Cleanup, clickManage Profiles…, and create a new profile namedTeamStandard. Enable the following actions:- Format code
- Reformat code
- Remove unused usings
- Sort usings
- Rename symbols to match naming rules
- Apply code style settings (e.g., indent size, line break style)
- Run the cleanup on the entire solution. In the
Code Cleanupdialog, select theTeamStandardprofile and clickRun on Entire Solution. Rider will process all files, applying formatting and naming changes.Run this as a one‑off operation after the settings import; subsequent edits will automatically follow the rules.
- Commit the resulting changes. Review the diff in your Git client. The only differences should be formatting, naming, and usings. Commit and push to the shared branch.
Example Git command (run in the solution root):
git add . # Verify only formatting changes git diff --cached --name-status git commit -m "Apply team code style via Rider Code Cleanup" git push
Expected Checks
- After the cleanup,
Inspection Settingsshould report zero style warnings for any file opened. - Running
Code Cleanupon a single file should produce a diff that only contains expected spacing and naming changes. - Another developer cloning the repo and importing the
settings.zipshould see identical results when they runCode Cleanup—no additional diffs. - Source control should contain the
.editorconfigorsettings.zipfile, and a fresh clone should automatically apply the rules on first load.
Recovery Options
- If a cleanup commit introduces unwanted changes, revert the commit with
git revertorgit reset --hard HEAD~1(be careful with shared branches). - Use Rider’s
Local Historyto roll back to a pre‑cleanup state if the IDE was open during cleanup. - To adjust a rule that is too aggressive, edit the
TeamStandardprofile: uncheck the offending action or modify the setting inCode Styleand re‑run cleanup. Commit the updated profile to the repo.
Limitations & Practical Checks
- Rider’s Code Style rules are version‑specific; a major update can change defaults. Keep the team on the same minor version or lock the
settings.zipto a specific Rider version.Check the Rider version with
Help | Aboutand record it in aRIDER_VERSIONfile in the repo. - Solution‑wide Analysis can be memory intensive. If performance suffers, disable
Analyze solution on loadand runCode Cleanupmanually when needed. - Importing shared settings will overwrite local preferences. Export personal settings first, or instruct developers to keep a separate
settings-personal.zipand merge manually.
Concrete Example: .editorconfig Snippet
Below is a minimal .editorconfig that enforces PascalCase for public members, snake_case for private fields, and 4‑space indentation. Rider reads this file automatically if it resides in the solution root.
# Top‑level EditorConfig file for .NET projects
root = true
[*.cs]
# Indentation
indent_style = space
indent_size = 4
# Line endings
end_of_line = crlf
# Naming rules
dotnet_naming_rule.public_members_should_be_pascal_case.symbols = public
# public symbols are those declared with the public keyword
dotnet_naming_symbols.public.applicable_kinds = field,property,method
# Apply rule to fields, properties, methods
dotnet_naming_symbols.public.applicable_accessibilities = public
dotnet_naming_symbols.public.required_prefix =
dotnet_naming_symbols.public.required_suffix =
# Rule definition
# Public members must be PascalCase
dotnet_naming_rule.public_members_should_be_pascal_case.style = pascal_case
# Private fields snake_case
dotnet_naming_rule.private_fields_should_be_snake_case.symbols = private_fields
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_fields.required_prefix = _
dotnet_naming_symbols.private_fields.required_suffix =
# Rule definition
dotnet_naming_rule.private_fields_should_be_snake_case.style = snake_case
Verification Checklist
- Open a file in Rider; the
Inspection Resultswindow shows no style warnings. - Run
Code Cleanupon a file and confirm the diff only contains formatting changes. - Clone the repo on a fresh machine, import the
settings.zip, and runCode Cleanup—the diff should be empty. - Check the Git history for
.editorconfigorsettings.zipand confirm they are tracked.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.