A collection of GitHub Copilot AI rules for .NET development best practices.
Tip
You can enhance Copilot's chat responses by providing it with contextual details about your team's workflow, tools, or project specifics.
This set of rules is a good starting point and should be customized to fit your specific needs. You can add or remove rules as necessary.
Rules for writing clean, maintainable C# code:
- ✨ Modern C# coding patterns
- 🧪 Testing best practices
- 📁 Code organization
- 🛡️ Error handling
- 🔌 Dependency management
- Code-generation instructions
- Test-generation instructions
⏳ Git
- Commit message generation instructions
Prompt files (prompts) let you build and share reusable prompt instructions with additional context.
- Pros and Cons Prompt - prompts/pros-and-cons.prompt.md
See more at Custom instructions for GitHub Copilot in VS Code
Copy the relevant rules you want to use into your project's .vscode/rules
directory and configure github.copilot.chat.codeGeneration.instructions
.
Here is an example of how to set up your .vscode/settings.json
file:
{
"github.copilot.chat.codeGeneration.instructions": [
{
"file": ".vscode/rules/csharp/coding-guidelines.md"
},
{
"file": ".vscode/rules/csharp/coding-style.md"
}
],
"github.copilot.chat.reviewSelection.enabled": true,
"github.copilot.chat.testGeneration.instructions": [
{
"file": ".vscode/rules/csharp/testing-xunit.md"
}
],
"chat.promptFiles": true,
"chat.promptFilesLocations": {
".github/prompts": true,
".vscode/prompts": true
}
}
If you want to build a successful and maintainable project, ensuring your code is clean, maintainable, and idiomatic is crucial. This is where coding guidelines come into play.
Coding guidelines promote consistency, readability, and maintainability within a project. Documenting these guidelines helps developers adhere to best practices, streamline collaboration, and minimize technical debt.
As AI coding tools and agents become integral team members, clear coding guidelines are more important than ever. These tools assist in generating, refactoring, and reviewing code, but they rely on well-defined rules to align with project standards. Documenting coding guidelines provides essential context, ensuring AI-generated code maintains consistency, readability, and best practices. Without structured rules, AI contributions may introduce inconsistencies, increasing technical debt and maintenance overhead.
Document your coding guidelines so it can be consumed by AI tools. Not only it can be used for additional context for code generation, but also now you can chat with LLMs about your coding guidelines. It becomes integral part of your project.
💡 For example, you can ask Copilot for a review of your code and it will be able to refer to the coding guidelines you provided.
With an introduction of Agent Mode it is even more important to have clear guidelines otherwise how you expect consistency and independence from AI agents?
Inspired by https://github.com/Aaronontheweb/dotnet-cursor-rules