This guide provides comprehensive documentation for using roslyn-diff from the command line.
The most common usage is comparing two source files:
roslyn-diff diff old.cs new.csThis will:
- Automatically detect the file type from the extension
- Use Roslyn semantic diff for
.csfiles - Output a unified diff to the console
Get help for any command:
roslyn-diff --help
roslyn-diff diff --help
roslyn-diff class --helpCompare two files and display the differences.
roslyn-diff diff <old-file> <new-file> [options]| Argument | Description |
|---|---|
<old-file> |
Path to the original (old) file |
<new-file> |
Path to the modified (new) file |
Controls how the diff is performed:
# Auto-detect mode (default)
roslyn-diff diff old.cs new.cs -m auto
# Force Roslyn semantic diff
roslyn-diff diff old.cs new.cs -m roslyn
# Force line-by-line diff
roslyn-diff diff old.cs new.cs -m lineMode values:
auto- Automatically select based on file extension.csfiles use C# Roslyn differ.vbfiles use VB.NET Roslyn differ- All other files use line-by-line diff
roslyn- Force semantic diff (only works with.csand.vbfiles)line- Force line-by-line diff (works with any text file)
Ignore whitespace differences when comparing:
roslyn-diff diff old.cs new.cs -w
roslyn-diff diff old.cs new.cs --ignore-whitespaceThis is useful when:
- Comparing files with different indentation styles
- Ignoring trailing whitespace changes
- Comparing files reformatted by different tools
Ignore comment differences (only effective in Roslyn mode):
roslyn-diff diff old.cs new.cs -c
roslyn-diff diff old.cs new.cs --ignore-commentsThis is useful when:
- Focusing on code logic changes only
- Ignoring documentation updates
- Comparing files with different comment styles
Control how many lines of unchanged context appear around changes:
# Show 5 lines of context
roslyn-diff diff old.cs new.cs -C 5
roslyn-diff diff old.cs new.cs --context 5
# Show no context
roslyn-diff diff old.cs new.cs -C 0Default: 3
Specify the output format:
roslyn-diff diff old.cs new.cs -o json
roslyn-diff diff old.cs new.cs --output htmlAvailable formats:
text- Unified diff format (default)json- Machine-readable JSONhtml- Interactive HTML reportplain- Plain text without ANSI codesterminal- Rich terminal output with colors
Write output to a file instead of stdout:
roslyn-diff diff old.cs new.cs -o json --out-file diff.json
roslyn-diff diff old.cs new.cs -o html --out-file report.htmlEnable rich terminal output with colors and formatting:
roslyn-diff diff old.cs new.cs --rich
roslyn-diff diff old.cs new.cs -rThis uses Spectre.Console for enhanced visual presentation.
# Basic comparison
roslyn-diff diff before/Service.cs after/Service.cs
# JSON output for CI/CD integration
roslyn-diff diff old.cs new.cs -o json --out-file result.json
# HTML report with custom context
roslyn-diff diff old.cs new.cs -o html -C 5 --out-file report.html
# Compare ignoring whitespace and comments
roslyn-diff diff old.cs new.cs -w -c
# Force line diff on a .cs file
roslyn-diff diff old.cs new.cs -m line
# Rich terminal output
roslyn-diff diff old.cs new.cs --richCompare specific classes between two files. This is useful for:
- Comparing specific classes in large files
- Tracking refactored classes across renames
- Comparing different implementations of an interface
roslyn-diff class <old-spec> <new-spec> [options]| Argument | Description |
|---|---|
<old-spec> |
Old file specification |
<new-spec> |
New file specification |
Specification format:
file.cs:ClassName- Specify a particular classfile.cs- Use the first class in the file (or auto-match)
Control how classes are matched between files:
roslyn-diff class old.cs new.cs --match-by exact
roslyn-diff class old.cs new.cs -m similarityMatch strategies:
exact- Match classes by exact name onlyinterface- Match classes that implement a specified interfacesimilarity- Match classes by content similarity (useful for renamed classes)auto- Try exact match first, fall back to similarity (default)
Specify the interface name when using interface matching:
roslyn-diff class old.cs new.cs --match-by interface --interface IRepository
roslyn-diff class old.cs new.cs -m interface -i IUserServiceSet the content similarity threshold (0.0 to 1.0):
roslyn-diff class old.cs new.cs --match-by similarity --similarity 0.7
roslyn-diff class old.cs new.cs -m similarity -s 0.9Default: 0.8 (80% similarity)
Same as the diff command:
roslyn-diff class old.cs:Foo new.cs:Foo -o jsonWrite output to a file:
roslyn-diff class old.cs:Foo new.cs:Foo -o html -f comparison.html# Compare same-named classes
roslyn-diff class before/Service.cs:UserService after/Service.cs:UserService
# Compare classes with different names (explicit)
roslyn-diff class old.cs:OldName new.cs:NewName
# Auto-find matching class in new file
roslyn-diff class old.cs:UserService new.cs --match-by similarity
# Find class implementing interface
roslyn-diff class old.cs new.cs --match-by interface --interface IRepository
# High similarity threshold for precise matching
roslyn-diff class old.cs:Foo new.cs --match-by similarity --similarity 0.95
# Generate JSON comparison
roslyn-diff class old.cs:Service new.cs:Service -o json --out-file class-diff.jsonProduces unified diff format similar to git diff:
roslyn-diff diff old.cs new.cs -o textOutput:
--- old/Calculator.cs
+++ new/Calculator.cs
@@ class Calculator @@
- public int Subtract(int a, int b)
- {
- return a - b;
- }
+ public int Subtract(int a, int b) => a - b;Machine-readable JSON format for integration with other tools:
roslyn-diff diff old.cs new.cs -o jsonInteractive HTML report:
roslyn-diff diff old.cs new.cs -o html --out-file report.htmlPlain text without ANSI escape codes:
roslyn-diff diff old.cs new.cs -o plainRich terminal output with colors (requires terminal support):
roslyn-diff diff old.cs new.cs -o terminal
# or
roslyn-diff diff old.cs new.cs --richOptions can be combined for fine-grained control:
# Full-featured comparison
roslyn-diff diff old.cs new.cs \
--ignore-whitespace \
--ignore-comments \
--context 5 \
--output html \
--out-file detailed-report.htmlUse plain text format for piping to other tools:
# Pipe to grep
roslyn-diff diff old.cs new.cs -o plain | grep "Method"
# Count changes
roslyn-diff diff old.cs new.cs -o json | jq '.summary.totalChanges'Use JSON output for script processing:
#!/bin/bash
# Get diff as JSON
diff_result=$(roslyn-diff diff old.cs new.cs -o json)
# Extract statistics
total=$(echo "$diff_result" | jq '.summary.totalChanges')
additions=$(echo "$diff_result" | jq '.summary.additions')
echo "Total changes: $total"
echo "Additions: $additions"Generate reports for continuous integration:
# In your CI script
roslyn-diff diff src/old.cs src/new.cs -o json --out-file diff-report.json
# Check for breaking changes
roslyn-diff diff old.cs new.cs -o json | jq -e '.summary.deletions == 0'- Use
auto(default) for most cases - Use
roslynwhen you specifically need semantic analysis - Use
linefor non-.NET files or when you want simple text diff
| Use Case | Recommended Format |
|---|---|
| Quick review | text or terminal |
| CI/CD pipelines | json |
| Code reviews | html |
| Scripting/piping | plain |
- Use more context (
-C 5or higher) for complex changes - Use less context (
-C 0or-C 1) for quick overview
For large files with many changes:
- Use
classcommand to focus on specific classes - Generate HTML report for easier navigation
- Use JSON format for programmatic analysis
When classes have been renamed:
roslyn-diff class old.cs:OldClassName new.cs --match-by similarityWhen matching by interface:
roslyn-diff class old.cs new.cs --match-by interface --interface IServiceProcess multiple files with a shell loop:
for file in src/*.cs; do
old_file="old/$file"
if [ -f "$old_file" ]; then
roslyn-diff diff "$old_file" "$file" -o json --out-file "diffs/$(basename $file).json"
fi
doneIf the diff seems incorrect:
- Try line mode (
-m line) to see raw differences - Check if whitespace (
-w) or comments (-c) are affecting results - Increase context (
-C 10) for more visibility