A specialized collection of GitHub Copilot customizations focused on C# and .NET development
This repository extends the official awesome-copilot repository with specialized C# and .NET development instructions, prompts, and chat modes.
Enhance GitHub Copilot's behavior for C# development with specialized instruction sets:
- C# Development - Core C# development guidelines and best practices
- Async Programming - Async/await patterns and best practices
- Testing Best Practices - Unit testing, integration testing, and TDD
- Entity Framework Core - EF Core patterns and optimization
Ready-to-use prompt templates for specific C# development scenarios:
- C# Async Best Practices - Analyze and improve async patterns
- Documentation Generator - Generate comprehensive XML documentation
- Performance Analyzer - Memory allocation analysis and performance optimization
Specialized chat modes for different development workflows:
- C# Mentor - Expert C# development guidance
- 4.1 Beast Mode - High-performance coding assistant
- Claude C# Beast - Claude Sonnet 4 powered C# expert agent
GitHub Copilot Instructions automatically enhance Copilot's behavior for your entire workspace. Here's how to use them effectively:
-
Copy instruction files to your project's
.github/folder:your-project/ βββ .github/ βββ copilot-instructions.md # Main C# guidelines βββ instructions/ βββ csharp-async-programming.instructions.md βββ csharp-testing.instructions.md βββ entity-framework-core.instructions.md -
Instructions activate automatically when you open VS Code in that workspace
-
No restart required - Copilot immediately uses the new guidelines
- Code Generation: Copilot follows C# best practices when suggesting code
- Code Completion: Suggestions align with your project's patterns
- Chat Responses: Copilot Chat provides C#-specific guidance
- Code Reviews: Copilot considers your guidelines when reviewing code
Before (generic suggestion):
public async Task<string> GetData()
{
var result = await httpClient.GetStringAsync(url);
return result;
}After (with async instructions):
public async Task<string> GetDataAsync(CancellationToken cancellationToken = default)
{
var result = await httpClient.GetStringAsync(url, cancellationToken).ConfigureAwait(false);
return result;
}Prompts are specialized commands you can run in GitHub Copilot Chat for specific tasks.
- Install a prompt by opening it in VS Code and clicking the install button
- Use in chat with
/prompt-namesyntax - Target specific code by selecting text before running the prompt
1. Select your async method in the editor
2. Open Copilot Chat (Ctrl+Shift+I)
3. Type: /csharp-async-best-practices
4. Get detailed analysis and improvements
Sample Output:
β
Good Practices Found
- Proper async method naming with Async suffix
- Correct Task<T> return type
β οΈ Issues Identified
- Missing ConfigureAwait(false) on line 15
- CancellationToken not passed to inner calls
π§ Recommended Improvements
[Detailed code examples with fixes]
Chat Modes are specialized AI personalities for different development scenarios.
π C# Mentor Mode
- Use when: Learning new concepts, code reviews, architecture decisions
- Example conversation:
You: "Should I use records or classes for my API DTOs?" Mentor: "For API DTOs, I recommend records because: 1. Immutability prevents accidental modification 2. Built-in equality comparison 3. Concise syntax reduces boilerplate Here's an example: public record UserDto(int Id, string Name, string Email); This automatically provides proper equality, ToString(), and serialization behavior."
β‘ Beast Mode
- Use when: High-performance coding, complex algorithms, optimization
- Example conversation:
You: "Optimize this LINQ query for large datasets" Beast: "Here's a high-performance approach using Span<T> and vectorization: [Provides optimized code with detailed performance analysis]"
- Install the chatmode file via VS Code Command Palette
- Switch modes in the Copilot Chat interface
- Context persists throughout your conversation
.github/
βββ copilot-instructions.md # Main C# development instructions
βββ instructions/ # Specialized instruction sets
β βββ csharp-async-programming.instructions.md
β βββ csharp-testing.instructions.md
β βββ entity-framework-core.instructions.md
βββ prompts/ # Reusable prompt templates
β βββ csharp-async-best-practices.prompt.md
β βββ csharp-documentation-generator.prompt.md
β βββ csharp-performance-analyzer.prompt.md
βββ chatmodes/ # Custom chat modes
βββ csharp-mentor.chatmode.md
βββ 4.1-Beast.chatmode.md
βββ Claude-CSharp-Beast.chatmode.md
Our instructions help Copilot suggest the latest C# features:
// Primary constructors with field keyword
public class UserService(IUserRepository repository) : IUserService
{
private readonly field = repository ?? throw new ArgumentNullException(nameof(repository));
public async Task<User> GetUserAsync(int id)
{
return await field.GetByIdAsync(id);
}
}
// Collection expressions
List<string> names = ["Alice", "Bob", "Charlie"];
int[] numbers = [1, 2, 3, 4, 5];Instructions ensure proper null handling:
// β
Copilot suggests proper null checks
public string FormatUserName(User? user)
{
return user is not null
? $"{user.FirstName} {user.LastName}"
: "Unknown User";
}
// β
Copilot avoids unnecessary null checks when type system guarantees non-null
public void ProcessValidUser(User user) // Never null based on context
{
Console.WriteLine(user.Name); // No null check needed
}Generate modern API controllers with proper patterns:
[ApiController]
[Route("api/[controller]")]
public class UsersController(IUserService userService) : ControllerBase
{
[HttpGet("{id:int}")]
[ProducesResponseType<UserDto>(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<UserDto>> GetUserAsync(
int id,
CancellationToken cancellationToken = default)
{
var user = await userService.GetUserAsync(id, cancellationToken);
return user is not null
? Ok(user.ToDto())
: NotFound();
}
}Get optimized data access patterns:
public class UserRepository(AppDbContext context) : IUserRepository
{
public async Task<User?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
{
return await context.Users
.Include(u => u.Profile)
.FirstOrDefaultAsync(u => u.Id == id, cancellationToken);
}
public async Task<IReadOnlyList<User>> GetActiveUsersAsync(CancellationToken cancellationToken = default)
{
return await context.Users
.Where(u => u.IsActive)
.AsNoTracking() // Performance optimization for read-only queries
.ToListAsync(cancellationToken);
}
}Instructions guide proper test structure:
public class UserServiceTests
{
private readonly Mock<IUserRepository> _mockRepository;
private readonly UserService _userService;
public UserServiceTests()
{
_mockRepository = new Mock<IUserRepository>();
_userService = new UserService(_mockRepository.Object);
}
[Fact]
public async Task GetUserAsync_WithValidId_ReturnsUser()
{
// Arrange
var userId = 1;
var expectedUser = new User { Id = userId, Name = "John Doe" };
_mockRepository.Setup(r => r.GetByIdAsync(userId, default))
.ReturnsAsync(expectedUser);
// Act
var result = await _userService.GetUserAsync(userId);
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(userId);
result.Name.Should().Be("John Doe");
}
[Fact]
public async Task GetUserAsync_WithInvalidId_ReturnsNull()
{
// Arrange
_mockRepository.Setup(r => r.GetByIdAsync(999, default))
.ReturnsAsync((User?)null);
// Act
var result = await _userService.GetUserAsync(999);
// Assert
result.Should().BeNull();
}
}Get complete API testing setups:
public class UsersControllerIntegrationTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
private readonly HttpClient _client;
public UsersControllerIntegrationTests(WebApplicationFactory<Program> factory)
{
_factory = factory;
_client = _factory.CreateClient();
}
[Fact]
public async Task GetUser_ReturnsSuccessAndCorrectContentType()
{
// Act
var response = await _client.GetAsync("/api/users/1");
// Assert
response.EnsureSuccessStatusCode();
response.Content.Headers.ContentType?.ToString()
.Should().Be("application/json; charset=utf-8");
}
}Instructions help organize code properly:
src/
βββ YourApp.Domain/ # Business logic & entities
β βββ Entities/
β βββ Interfaces/
β βββ ValueObjects/
βββ YourApp.Application/ # Use cases & services
β βββ Services/
β βββ DTOs/
β βββ Interfaces/
βββ YourApp.Infrastructure/ # Data access & external services
β βββ Data/
β βββ Repositories/
β βββ Services/
βββ YourApp.Web/ # API controllers & startup
βββ Controllers/
βββ Middleware/
βββ Program.cs
Get proper DI configuration:
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Domain services
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
// Infrastructure
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// Add health checks
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>();
var app = builder.Build();
// Configure middleware pipeline
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHealthChecks("/health");
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();- Select problematic code in your editor
- Run:
/csharp-async-best-practicesin Copilot Chat - Get: Detailed analysis with specific improvements
- Apply: Suggested changes with explanations
- Switch to: C# Mentor chat mode
- Ask: "How do I implement the Repository pattern with EF Core?"
- Get: Complete example with explanations and best practices
- Follow up: With specific questions about implementation details
- Switch to: Beast Mode chat mode
- Share: Your performance-critical code
- Get: Optimized version with benchmarks and explanations
- Learn: Advanced techniques like
Span<T>, vectorization, memory management
- Select: Your public API methods
- Run:
/csharp-documentation-generator - Get: Complete XML documentation with examples
- Customize: Based on your project's documentation standards
We welcome contributions! Here's how you can help improve this collection.
Add specialized guidelines for specific C# scenarios:
Example: API Security Instructions
---
description: 'Security best practices for ASP.NET Core APIs'
applyTo: '**/Controllers/*.cs'
---
# API Security Guidelines
## Authentication & Authorization
- Always validate JWT tokens properly
- Use [Authorize] attributes on controllers
- Implement role-based access control (RBAC)
[... detailed guidelines ...]Create automation prompts for common development tasks:
Example: Database Migration Prompt
---
name: ef-migration-generator
description: Generate Entity Framework Core migrations with proper naming
---
# EF Core Migration Generator
Analyze the current DbContext changes and generate:
1. Descriptive migration name
2. Migration command
3. Rollback instructions
4. Testing recommendations
Design specialized AI assistants:
Example: Performance Analyzer Mode
---
name: csharp-performance-analyzer
description: Specialized in C# performance optimization
model: gpt-4o
---
You are a C# performance expert focused on:
- Memory allocation analysis
- Garbage collection optimization
- Algorithm complexity assessment
- Benchmarking recommendations
git clone https://github.com/your-username/awesomeCopilot.git
git clone https://github.com/fkucukkara/awesome-copilot-csharp.git
cd awesomeCopilotCSHARPgit checkout -b feature/new-performance-instructionsPlace files in the appropriate directory:
- Instructions:
.github/instructions/ - Prompts:
.github/prompts/ - Chat Modes:
.github/chatmodes/
- Test instructions: Create a sample C# project and verify Copilot behavior
- Test prompts: Install and run in VS Code, check output quality
- Test chat modes: Engage in conversations, verify responses
Add your contribution to:
- README.md (this file)
- Any relevant section documentation
Include in your PR:
- Clear description of what you've added
- Testing evidence (screenshots, examples)
- Use cases where your contribution helps
- Create a new C# project
- Copy your instruction file to
.github/ - Write sample code and verify Copilot suggestions follow your guidelines
- Test both code completion and chat responses
- Install your prompt in VS Code
- Test with various code examples
- Verify output matches expected format
- Check error handling with invalid inputs
- Install and activate the chat mode
- Have conversations covering different scenarios
- Verify the AI maintains the intended personality
- Test knowledge boundaries and accuracy
Symptoms: Copilot suggestions don't follow your custom guidelines
Solutions:
- Check file location: Instructions must be in
.github/folder - Verify file extension: Must end with
.instructions.md - Restart VS Code: Sometimes needed for new instructions
- Check syntax: YAML frontmatter must be valid
Example fix:
---
description: 'Your description here' # Quotes required
applyTo: '**/*.cs' # Proper glob pattern
---Symptoms: Can't use /your-prompt-name in Copilot Chat
Solutions:
- Install properly: Use VS Code's install button on the prompt file
- Check naming: Prompt name in YAML must match filename
- Restart chat: Close and reopen Copilot Chat
- Verify VS Code version: Needs recent VS Code with Copilot Chat
Symptoms: Chat mode doesn't activate or behaves incorrectly
Solutions:
- Check model availability: Ensure specified model is accessible
- Verify tools: Some chat modes require specific VS Code extensions
- Reset chat: Start a new conversation
- Check syntax: YAML frontmatter must be valid
- Be specific: Target exact file patterns with
applyTo - Keep focused: One instruction file per domain (async, testing, etc.)
- Use examples: Include code examples in instructions
- Clear objectives: State exactly what the prompt should do
- Expected format: Define output structure
- Error handling: Include guidance for edge cases
- Consistent personality: Maintain the same tone throughout
- Domain expertise: Focus on specific areas of knowledge
- Helpful responses: Always provide actionable advice
- Check existing issues in the repository
- Create detailed issue with reproduction steps
- Include environment info (VS Code version, Copilot version)
- Check documentation in this README
- Look at examples in existing files
- Ask in discussions for help with contributions
- Join discussions about new features
- Propose improvements to existing content
- Share your use cases to help others
- VS Code Copilot Customization Documentation - Official guide to customizing Copilot
- GitHub Copilot Chat Documentation - Complete chat feature documentation
- Official Awesome Copilot Repository - Main community repository
- Microsoft .NET Documentation - Official .NET documentation
- C# Language Reference - Complete C# language guide
.github/
βββ copilot-instructions.md # π― Main C# guidelines (always include)
βββ instructions/ # π Specialized rules
β βββ csharp-async-programming.instructions.md # Async/await patterns
β βββ csharp-testing.instructions.md # Testing best practices
β βββ entity-framework-core.instructions.md # EF Core optimization
βββ prompts/ # π― Automation commands
β βββ csharp-async-best-practices.prompt.md # Async code analysis
β βββ csharp-documentation-generator.prompt.md # XML doc generation
β βββ csharp-performance-analyzer.prompt.md # Performance analysis
βββ chatmodes/ # π§© AI assistants
βββ csharp-mentor.chatmode.md # Learning & guidance
βββ 4.1-Beast.chatmode.md # High-performance coding
βββ Claude-CSharp-Beast.chatmode.md # Advanced C# expert
| Command | Purpose | Best Used For |
|---|---|---|
/csharp-async-best-practices |
Analyze async code patterns | Code reviews, performance optimization |
/csharp-documentation-generator |
Generate XML documentation | API documentation, code completion |
/csharp-performance-analyzer |
Memory allocation and performance analysis | Performance optimization, bottleneck identification |
| Mode | Personality | Use Cases |
|---|---|---|
| C# Mentor | π Patient teacher | Learning, explanations, best practices |
| Beast Mode | β‘ Performance expert | Optimization, algorithms, advanced patterns |
| Claude C# Beast | π Advanced expert | Complex architecture, design patterns |
| Pattern | Target Files | Purpose |
|---|---|---|
**/*.cs |
All C# files | General C# guidelines |
**/*Test.cs |
Test files only | Testing-specific rules |
**/*DbContext.cs |
EF DbContext files | Database-specific patterns |
**/Controllers/*.cs |
API controllers | Web API best practices |
- Copy:
copilot-instructions.mdto your.github/folder - Add: Relevant specialized instructions based on your tech stack
- Install: Useful prompts for your development workflow
- Select: Code to review in VS Code
- Run: Appropriate analysis prompt (e.g.,
/csharp-async-best-practices) - Apply: Suggested improvements
- Document: Changes with generated documentation
- Switch to: C# Mentor chat mode
- Ask: Specific questions about patterns, frameworks, or best practices
- Request: Examples and explanations
- Practice: Implementing suggested patterns
- Switch to: Beast Mode chat mode
- Share: Performance-critical code
- Get: Optimized implementations with benchmarks
- Test: Performance improvements in your application
---
description: 'Your project-specific C# guidelines'
applyTo: 'src/**/*.cs' # Target only your src folder
---
# Project-Specific Guidelines
## Domain Rules
- Use your business domain terminology
- Follow your specific naming conventions
- Include your architecture patterns
## Integration Requirements
- Include your specific logging patterns
- Add your error handling approaches
- Document your testing strategies---
name: your-custom-prompt
description: Extended version of existing prompt
author: your-name
version: 1.0.0
extends: csharp-async-best-practices # Reference base prompt
---
# Enhanced Async Analysis
Include all base functionality plus:
- Your specific performance requirements
- Your logging standards
- Your error handling patterns
This project is licensed under the MIT License - see the LICENSE file for details.
- Built upon the foundation of github/awesome-copilot
- Inspired by the C# and .NET developer community
- Thanks to all contributors who help improve C# development with AI assistance
Happy Coding with GitHub Copilot and C#! π