GitHub Copilot AI rules for .NET development best practices. Helps operations teams enforce coding standards and improve code quality. Integrates with GitHub Copilot in Visual Studio Code.
git clone https://github.com/NikiforovAll/github-copilot-rules.gitGitHub Copilot Handbook provides ready-to-use customizations for GitHub Copilot in VS Code, including coding guidelines, style conventions, test generation rules, and custom agents. The collection includes path-specific instructions for enforcing .NET best practices, reusable prompt templates, and specialized agent modes for code review, debugging, and analysis. Teams can copy files into their project's .github/ directory and configure VS Code settings to apply these rules automatically. This approach helps development and operations teams maintain consistent coding standards, improve code quality, and streamline common development workflows like commit message generation and test creation.
1. **Identify a Coding Standard**: Determine a .NET coding standard or pattern you want to enforce (e.g., 'Use 'using' statements for IDisposable objects'). 2. **Define the Rule**: Use the prompt template to generate a GitHub Copilot AI rule. Customize the rule name, description, and code examples to fit your specific need. 3. **Add to Repository**: Save the rule in a `.github/copilot-rules.json` file in your repository root. Commit and push the file to GitHub. 4. **Test the Rule**: Open a file in Visual Studio Code with GitHub Copilot enabled. Introduce a violation of the rule (e.g., an async void method) and verify that GitHub Copilot flags it with an error or warning. 5. **Refine and Iterate**: Adjust the rule severity (error/warning) or pattern based on feedback from your team. Monitor GitHub Copilot's suggestions to ensure they align with your team's standards. **Tip**: Start with 2-3 high-impact rules (e.g., async void, IDisposable usage) to quickly see the benefits. Gradually add more rules as your team adopts the practice.
Enforce .NET coding standards across development teams
Auto-generate conventional commit messages in GitHub
Run structured code reviews with prioritized feedback
Generate xUnit tests following team conventions
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/NikiforovAll/github-copilot-rulesCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Generate a GitHub Copilot AI rule for [RULE_NAME] in .NET development. The rule should enforce [STANDARD/PATTERN] for [CODE_CONTEXT]. Include a clear explanation of the rule, why it matters, and a code snippet showing the correct and incorrect implementation. Example: 'Generate a GitHub Copilot AI rule for 'Avoid async void methods' in .NET. Explain why this rule matters for error handling and thread safety, and provide a code snippet showing the correct (async Task) and incorrect (async void) implementations.'
```markdown
# GitHub Copilot AI Rule: Avoid Async Void Methods in .NET
## Rule Description
This rule enforces the use of `async Task` instead of `async void` for asynchronous methods in .NET. Async void methods cannot be awaited, making error handling and debugging significantly more difficult. This rule applies to all public and protected methods in your codebase.
## Why This Matters
- **Error Handling**: Exceptions thrown in async void methods cannot be caught by try/catch blocks, leading to unhandled exceptions.
- **Debugging**: Stack traces for async void methods are less informative, making it harder to identify the source of errors.
- **Thread Safety**: Async void methods can cause deadlocks or race conditions in multi-threaded scenarios.
## Correct Implementation
```csharp
public async Task FetchDataAsync()
{
var data = await _httpClient.GetStringAsync("https://api.example.com/data");
_logger.LogInformation("Data fetched successfully: {Data}", data);
}
```
## Incorrect Implementation
```csharp
public async void FetchDataAsync()
{
var data = await _httpClient.GetStringAsync("https://api.example.com/data");
_logger.LogInformation("Data fetched successfully: {Data}", data);
}
```
## How to Enforce This Rule
1. Add this rule to your `.github/copilot-rules.json` file:
```json
{
"rules": [
{
"name": "Avoid Async Void Methods",
"description": "Enforce async Task over async void for all methods.",
"pattern": "async void",
"severity": "error",
"message": "Async void methods are not allowed. Use 'async Task' instead."
}
]
}
```
2. Commit the file to your repository.
3. GitHub Copilot will now flag any violations of this rule in your code.
```Hey, what’s on your mind today?
Get more done every day with Microsoft Teams – powered by AI
Automate security compliance and monitor real-time security posture seamlessly.
Automate your spreadsheet tasks with AI power
Agentic AI Workflow platform
Connected workspace for docs, wikis, and projects
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan