Skip to main content
subagent official · GitHub

C#/.NET Janitor — GitHub Copilot subagent: features and install

Cleans up and modernizes C# and .NET codebases by resolving technical debt, adding tests, and applying modern language features.

Install into GitHub Copilot · Manually: put the files in place All methods and platforms ↓
.github/agents/csharp-dotnet-janitor.agent.md
Open on GitHub

What C#/.NET Janitor does

This subagent automates routine maintenance across C# codebases. It follows a strict analysis sequence: scanning for compiler warnings, locating obsolete APIs, finding missing tests, and reviewing memory allocations. From there, it applies modern language features such as collection expressions, pattern matching, and primary constructors while cleaning up unused using statements.

The subagent connects to the microsoft.docs.mcp tool to verify migration guidelines and syntax rules against official Microsoft documentation. Every change is applied in small increments. The agent executes tests in the terminal after each modification.

A working test suite is required for safe execution. Because the subagent is instructed to run tests after every single modification, running it inside an untested codebase disables its primary safeguard against breaking changes.

What it helps with

  • upgrade legacy C# code to modern language features like collection expressions
  • eliminate unused using statements and resolve compiler warnings
  • optimize memory allocations with Span<T> and StringBuilder
  • generate missing unit tests using AAA and FluentAssertions
  • write XML documentation comments for public APIs

Example prompts for the agent

  • Modernize class models to use C# primary constructors and collection expressions.
  • Scan the solution for compiler warnings and unused using directives.
  • Add unit tests with FluentAssertions for all public methods in the billing service.

How to install C#/.NET Janitor

Manually: put the files in place

.github/agents/csharp-dotnet-janitor.agent.md

Step by step, with commands for each platform: Claude Code subagents: how to create one, call it and keep context clean

Questions about C#/.NET Janitor

How to install C#/.NET Janitor in GitHub Copilot?

Save the agent configuration file to .github/agents/csharp-dotnet-janitor.agent.md. GitHub Copilot will recognize it as an available subagent.

What does C#/.NET Janitor do?

It inspects .NET projects, updates outdated syntax to current C# standards, fixes compiler warnings, and expands test coverage.

Why does the subagent use microsoft.docs.mcp?

It queries the microsoft.docs.mcp tool to pull recommended patterns, async guidelines, and official migration steps directly from Microsoft.

Source text

csharp-dotnet-janitor.agent.md · MIT
---
description: 'Perform janitorial tasks on C#/.NET code including cleanup, modernization, and tech debt remediation.'
name: 'C#/.NET Janitor'
tools: [vscode/extensions, vscode/getProjectSetupInfo, vscode/installExtension, vscode/newWorkspace, vscode/runCommand, vscode/vscodeAPI, execute/getTerminalOutput, execute/runTask, execute/createAndRunTask, execute/runTests, execute/runInTerminal, execute/testFailure, read/terminalSelection, read/terminalLastCommand, read/getTaskOutput, read/problems, read/readFile, 'github/*', 'microsoft.docs.mcp/*', edit/editFiles, search, web]
---
# C#/.NET Janitor

Perform janitorial tasks on C#/.NET codebases. Focus on code cleanup, modernization, and technical debt remediation.

## Core Tasks

### Code Modernization

- Update to latest C# language features and syntax patterns
- Replace obsolete APIs with modern alternatives
- Convert to nullable reference types where appropriate
- Apply pattern matching and switch expressions
- Use collection expressions and primary constructors

### Code Quality

- Remove unused usings, variables, and members
- Fix naming convention violations (PascalCase, camelCase)
- Simplify LINQ expressions and method chains
- Apply consistent formatting and indentation
- Resolve compiler warnings and static analysis issues

### Performance Optimization

- Replace inefficient collection operations
- Use `StringBuilder` for string concatenation
- Apply `async`/`await` patterns correctly
- Optimize memory allocations and boxing
- Use `Span<T>` and `Memory<T>` where beneficial

### Test Coverage

- Identify missing test coverage
- Add unit tests for public APIs
- Create integration tests for critical workflows
- Apply AAA (Arrange, Act, Assert) pattern consistently
- Use FluentAssertions for readable assertions

### Documentation

- Add XML documentation comments
- Update README files and inline comments
- Document public APIs and complex algorithms
- Add code examples for usage patterns

## Documentation Resources

Use `microsoft.docs.mcp` tool to:

- Look up current .NET best practices and patterns
- Find official Microsoft documentation for APIs
- Verify modern syntax and recommended approaches
- Research performance optimization techniques
- Check migration guides for deprecated features

Query examples:

- "C# nullable reference types best practices"
- ".NET performance optimization patterns"
- "async await guidelines C#"
- "LINQ performance considerations"

## Execution Rules

1. **Validate Changes**: Run tests after each modification
2. **Incremental Updates**: Make small, focused changes
3. **Preserve Behavior**: Maintain existing functionality
4. **Follow Conventions**: Apply consistent coding standards
5. **Safety First**: Backup before major refactoring

## Analysis Order

1. Scan for compiler warnings and errors
2. Identify deprecated/obsolete usage
3. Check test coverage gaps
4. Review performance bottlenecks
5. Assess documentation completeness

Apply changes systematically, testing after each modification.

© github · MIT · github/awesome-copilot

Similar subagents

All subagents for Code review and refactoring →

From the same set770

The whole set →
Defender Scout KQL Generates and optimizes KQL queries for Microsoft Defender Advanced Hunting across endpoints and email. Useful for threat detection and incident investigations. ★ 40,418repo stars Declarative Agents Architect Designs Microsoft 365 Copilot declarative agents using the v1.5 schema. Generates TypeSpec definitions, validates character constraints, and configures tooling. ★ 40,418repo stars Debug Mode Instructions A GitHub Copilot subagent that walks debugging in phases: reproduce the bug, find the root cause, patch it, verify. Useful when a failure is flaky and you don't know where to start. ★ 40,418repo stars C# MCP Server Expert Writes and debugs MCP servers in C#: tools, prompts, resources, dependency injection, stdio transport. Useful when you build on the ModelContextProtocol SDK. ★ 40,418repo stars Critical thinking mode instructions Forces the engineer to justify technical decisions by repeatedly asking "Why?". It questions assumptions without modifying project files. ★ 40,418repo stars Context7-Expert This subagent checks library documentation through Context7 and uses current syntax in its answers. Use it for framework and package questions. ★ 40,418repo stars Context Architect Plans and prepares multi-file changes across your codebase by tracing dependencies and imports. It maps affected areas and tests before writing any code. ★ 40,418repo stars VSCode Tour Expert Subagent that creates .tour files — interactive step-by-step codebase walkthroughs in VSCode CodeTour format. ★ 40,418repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor