Skip to main content
rule official · GitHub

dotnet-framework — GitHub Copilot rule: what it does, how to install

This rule guides Copilot through .NET Framework projects, from .csproj conventions to C# 7.3 limits. Use it when you want generated code and build advice to follow those constraints.

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

What dotnet-framework does

The rule applies to *.csproj and *.cs files. It tells Copilot to identify the project format first: legacy projects need new source files listed with <Compile>, while SDK-style projects follow SDK conventions. For builds, it directs the agent to use msbuild /t:rebuild rather than dotnet build.

Generated code must stay within C# 7.3. The rule also calls for ConfigureAwait(false) in library code and rejects blocking async calls such as .Result and .Wait(). It covers date handling, string operations, exception handling, configuration, and disposal practices.

NuGet installation and updates are off limits for the agent; package changes should go through the user and Visual Studio’s NuGet Package Manager. If your project targets a C# version above 7.3, check generated syntax against that target before using it.

What it helps with

  • build a .NET Framework project with msbuild
  • add a source file to a legacy .csproj
  • rewrite syntax that exceeds C# 7.3
  • remove blocking calls from asynchronous code
  • access app settings through ConfigurationManager

Example prompts for the agent

  • Add NewService.cs to this legacy project and update its .csproj for C# 7.3.
  • Check this asynchronous code for .Result and .Wait() and replace those calls.
  • Prepare a build for this .NET Framework solution using msbuild /t:rebuild.

How to install dotnet-framework

Manually: put the files in place

.github/instructions/dotnet-framework.instructions.md

The applyTo field sets which files it applies to

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about dotnet-framework

How do I install dotnet-framework in GitHub Copilot?

Add the rule file to your project at .github/instructions/dotnet-framework.instructions.md.

What does dotnet-framework do?

It guides Copilot on .NET Framework project files, builds, C# 7.3 syntax, NuGet changes, and common coding practices.

Can the agent update NuGet packages with this rule?

No. The rule directs the agent not to install or update packages; package changes should be handled by the user in Visual Studio’s NuGet Package Manager.

Source text

dotnet-framework.instructions.md · MIT
---
description: 'Guidance for working with .NET Framework projects. Includes project structure, C# language version, NuGet management, and best practices.'
applyTo: '**/*.csproj, **/*.cs'
---

# .NET Framework Development

## Build and Compilation Requirements
- Always use `msbuild /t:rebuild` to build the solution or projects instead of `dotnet build`

## Project File Management

### Legacy and SDK-Style Project Structure
Many .NET Framework projects use the legacy non-SDK project format, which differs significantly from modern SDK-style projects. However, SDK-style project files can also target .NET Framework, such as `net48` or `net472`. Check the `.csproj` format before applying project-file guidance:

- **Legacy non-SDK projects**: All new source files **MUST** be explicitly added to the project file (`.csproj`) using a `<Compile>` element
  - Legacy non-SDK projects do not automatically include files in the directory like SDK-style projects
  - Example: `<Compile Include="Path\To\NewFile.cs" />`

- **SDK-style projects**: If the project file has an `Sdk` attribute, use SDK-style conventions even when it targets .NET Framework
  - Example: `<Project Sdk="Microsoft.NET.Sdk">`
  - Uses `<TargetFramework>` instead of `<TargetFrameworkVersion>`
  - Example: `<TargetFramework>net48</TargetFramework>`

- **No Implicit Imports in legacy projects**: Unlike SDK-style projects, legacy non-SDK projects do not automatically import common namespaces or assemblies
 
- **Build Configuration in legacy projects**: Contains explicit `<PropertyGroup>` sections for Debug/Release configurations

- **Output Paths in legacy projects**: Explicit `<OutputPath>` and `<IntermediateOutputPath>` definitions

- **Target Framework in legacy projects**: Uses `<TargetFrameworkVersion>` instead of `<TargetFramework>`
  - Example: `<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>`

## NuGet Package Management
- Installing and updating NuGet packages in .NET Framework projects is a complex task requiring coordinated changes to multiple files. Therefore, **do not attempt to install or update NuGet packages** in this project.
- Instead, if changes to NuGet references are required, ask the user to install or update NuGet packages using the Visual Studio NuGet Package Manager or Visual Studio package manager console.
- When recommending NuGet packages, ensure they are compatible with .NET Framework or .NET Standard 2.0 (not only .NET Core or .NET 5+).

## C# Language Version is 7.3
- This project is limited to C# 7.3 features only. Please avoid using:

### C# 8.0+ Features (NOT SUPPORTED):
  - Using declarations (`using var stream = ...`)
  - Await using statements (`await using var resource = ...`)
  - Switch expressions (`variable switch { ... }`)
  - Null-coalescing assignment (`??=`)
  - Range and index operators (`array[1..^1]`, `array[^1]`)
  - Default interface methods
  - Readonly members in structs
  - Static local functions
  - Nullable reference types (`string?`, `#nullable enable`)

### C# 9.0+ Features (NOT SUPPORTED):
  - Records (`public record Person(string Name)`)
  - Init-only properties (`{ get; init; }`)
  - Top-level programs (program without Main method)
  - Pattern matching enhancements
  - Target-typed new expressions (`List<string> list = new()`)

### C# 10+ Features (NOT SUPPORTED):
  - Global using statements
  - File-scoped namespaces
  - Record structs
  - Required members

### Use Instead (C# 7.3 Compatible):
  - Traditional using statements with braces
  - Switch statements instead of switch expressions
  - Explicit null checks instead of null-coalescing assignment
  - Array slicing with manual indexing
  - Abstract classes or interfaces instead of default interface methods

## Environment Considerations (Windows environment)
- Use Windows-style paths with backslashes (e.g., `C:\path\to\file.cs`)
- Use Windows-appropriate commands when suggesting terminal operations
- Consider Windows-specific behaviors when working with file system operations

## Common .NET Framework Pitfalls and Best Practices

### Async/Await Patterns
- **ConfigureAwait(false)**: Always use `ConfigureAwait(false)` in library code to avoid deadlocks:
  ```csharp
  var result = await SomeAsyncMethod().ConfigureAwait(false);
  ```
- **Avoid sync-over-async**: Don't use `.Result` or `.Wait()` or `.GetAwaiter().GetResult()`. These sync-over-async patterns can lead to deadlocks and poor performance. Always use `await` for asynchronous calls.

### DateTime Handling
- **Use DateTimeOffset for timestamps**: Prefer `DateTimeOffset` over `DateTime` for absolute time points
- **Specify DateTimeKind**: When using `DateTime`, always specify `DateTimeKind.Utc` or `DateTimeKind.Local`
- **Culture-aware formatting**: Use `CultureInfo.InvariantCulture` for serialization/parsing

### String Operations
- **StringBuilder for concatenation**: Use `StringBuilder` for multiple string concatenations
- **StringComparison**: Always specify `StringComparison` for string operations:
  ```csharp
  string.Equals(other, StringComparison.OrdinalIgnoreCase)
  ```

### Memory Management
- **Dispose pattern**: Implement `IDisposable` properly for unmanaged resources
- **Using statements**: Always wrap `IDisposable` objects in using statements
- **Avoid large object heap**: Keep objects under 85KB to avoid LOH allocation

### Configuration
- **Use ConfigurationManager**: Access app settings through `ConfigurationManager.AppSettings`
- **Connection strings**: Store in `<connectionStrings>` section, not `<appSettings>`
- **Transformations**: Use web.config/app.config transformations for environment-specific settings

### Exception Handling
- **Specific exceptions**: Catch specific exception types, not generic `Exception`
- **Don't swallow exceptions**: Always log or re-throw exceptions appropriately
- **Use using for disposable resources**: Ensures proper cleanup even when exceptions occur

### Performance Considerations
- **Avoid boxing**: Be aware of boxing/unboxing with value types and generics
- **String interning**: Use `string.Intern()` judiciously for frequently used strings
- **Lazy initialization**: Use `Lazy<T>` for expensive object creation
- **Avoid reflection in hot paths**: Cache `MethodInfo`, `PropertyInfo` objects when possible

© github · MIT · github/awesome-copilot

Similar IDE rules

All IDE rules for Programming languages →

From the same set770

The whole set →
dotnet-wpf Directs GitHub Copilot to write WPF desktop code using the MVVM pattern on .NET 8.0+. It prevents business logic leaks into code-behind files. ★ 40,418repo stars dotnet-upgrade A GitHub Copilot rule for staged .NET upgrades, covering project dependencies, builds, tests, and CI/CD checks. ★ 40,418repo stars dotnet-maui This rule steers Copilot toward idiomatic .NET MAUI: MVVM, CollectionView over ListView, Shell navigation. Useful once the agent starts editing XAML and C#. ★ 40,418repo stars dotnet-maui-9-to-dotnet-maui-10-upgrade Guides .NET MAUI migrations from version 9 to 10 by updating TargetFrameworks, replacing internal MessagingCenter calls, and migrating obsolete UI controls. ★ 40,418repo stars devops-core-principles Guides GitHub Copilot on CALMS principles, DORA metrics, and delivery automation across CI/CD pipelines and infrastructure as code. ★ 40,418repo stars devcontainers Twelve rules that make Copilot review devcontainer.json, Dev Container Features and Codespaces lifecycle settings, each with the exact fix and a source. ★ 40,418repo stars devbox-image-definition A GitHub Copilot rule that helps you write YAML image definition files for Microsoft Dev Box Team Customizations. Useful when your customizations rely on ~/winget, ~/gitclone and ~/powershell tasks. ★ 40,418repo stars declarative-agents-microsoft365 Development instructions for Microsoft 365 Copilot declarative agents using schema v1.5. Helps build TypeSpec models and valid manifests. ★ 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