migrate-nullable-references
Ce qu’il fait
Cette compétence active les types de référence nullables dans un projet C# et traite les avertissements qu'ils font apparaître. Elle s'adresse aux équipes qui veulent que le compilateur détecte les valeurs manquantes avant qu'elles ne provoquent des plantages.
Quand l’utiliser
- ✓Quand vous voulez activer les types de référence nullables dans un projet C# existant.
- ✓Quand des avertissements de nullité CS86xx apparaissent après l'activation de cette fonctionnalité.
- ✓Quand l'API publique d'une bibliothèque a besoin d'annotations de nullabilité pour que les utilisateurs disposent d'informations exactes.
Lien du skill
https://github.com/dotnet/skills/blob/main/plugins/dotnet-upgrade/skills/migrate-nullable-references/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Active les types de référence nullables dans mon projet C# et corrige les avertissements fichier par fichier.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'agent active le paramètre, traite les avertissements dans un ordre planifié, ajoute des annotations exactes et supprime les opérateurs de pardon de nullité inutiles.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
Nullable Reference Migration
Enable C# nullable reference types (NRTs) in an existing codebase and systematically resolve all warnings. The outcome is a project (or solution) with <Nullable>enable</Nullable>, zero nullable warnings, and accurately annotated public API surfaces — giving both the compiler and consumers reliable nullability information.
When to Use
- Enabling nullable reference types in an existing C# project or solution
- Systematically resolving CS86xx nullable warnings after enabling the feature
- Annotating a library's public API surface so consumers get accurate nullability information
- Upgrading a dependency that has added nullable annotations and new warnings appear
- Analyzing suppressions in a code base that has already enabled NRTs to determine whether they can be removed
When Not to Use
- The project already has
<Nullable>enable</Nullable>and zero warnings — the migration is done unless the user wants to re-examine suppressions with a view to removing unnecessary ones (see Step 6) - The user only wants to suppress warnings without fixing them (recommend against this)
- The code targets C# 7.3 or earlier, which does not support nullable reference types
Inputs
| Input | Required | Description |
|---|---|---|
| Project or solution path | Yes | The .csproj, .sln, or build entry point to migrate |
| Migration scope | No | project-wide (default) or file-by-file — controls the rollout strategy |
| Build command | No | How to build the project (e.g., dotnet build, msbuild, or a repo-specific build script). Detect from the repo if not provided |
| Test command | No | How to run tests (e.g., dotnet test, or a repo-specific test script). Detect from the repo if not provided |
Workflow
🛑 Zero runtime behavior changes. NRT migration is strictly a metadata and annotation exercise. The generated IL must not change — no new branches, no new null checks, no changed control flow, no added or removed method calls. The only acceptable changes are nullable annotations (
?), nullable attributes ([NotNullWhen], etc.),!operators (metadata-only), and#nullabledirectives. If you discover a missing runtime null guard or a latent bug during migration, do not fix it inline. Instead, offer to insert a// TODO: Consider adding ArgumentNullException.ThrowIfNull(param)comment at the site so the user can address it as a separate change. Never mix behavioral fixes into an annotation commit.
Commit strategy: Commit at each logical boundary — after enabling
<Nullable>(Step 2), after fixing dereference warnings (Step 3), after annotating declarations (Step 4), after applying nullable attributes (Step 5), and after cleaning up suppressions (Step 6). This keeps each commit focused and reviewable, and prevents losing work if a later step reveals a design issue that requires rethinking. For file-by-file migrations, commit each file or batch of related files individually.
Step 1: Evaluate readiness
Optional: Run
scripts/Get-NullableReadiness.ps1 -Path <project-or-solution>to automate the checks below. The script reports<Nullable>,<LangVersion>,<TargetFramework>,<WarningsAsErrors>settings and counts#nullable disabledirectives,!operators, and#pragma warning disable CS86xxsuppressions. Use-Jsonfor machine-readable output.
- Identify how the project is built and tested. Look for build scripts (e.g.,
build.cmd,build.sh,Makefile), a.slnfile, or individual.csprojfiles. If the repo uses a custom build script, use it instead ofdotnet buildthroughout this workflow. - Run
dotnet --versionto confirm the SDK is installed. Nullable reference types (NRTs) require C# 8.0+ (.NET Core 3.0/.NET Standard 2.1or later). - Open the
.csproj(orDirectory.Build.propsif properties are set at the repo level) and check the<LangVersion>and<TargetFramework>. If the project multi-targets, note all TFMs.
Stop if the language version or target framework is insufficient. If
<LangVersion>is below 8.0, or the project targets a framework that defaults to C# 7.x (e.g.,.NET Framework 4.xwithout an explicit<LangVersion>), NRTs cannot be enabled as-is. Inform the user explicitly: explain what needs to change (set<LangVersion>8.0</LangVersion>or higher, or retarget to.NET Core 3.0+/.NET 5+), and ask whether they want to make that update and continue, or abort the
Questions fréquentes
Puis-je simplement masquer les avertissements ?
La compétence le déconseille et vise à corriger les avertissements pour que le compilateur fournisse des informations fiables.
Fonctionne-t-elle avec les anciennes versions de C# ?
Non. C# 7.3 ou une version antérieure ne prend pas en charge les types de référence nullables, donc ce code ancien ne peut pas suivre cette migration.
Puis-je migrer un fichier à la fois ?
Oui. La compétence prend en charge la migration fichier par fichier comme la migration à l'échelle du projet.
Détails
Description originale de l’auteur
Enable nullable reference types in a C# project and systematically resolve all warnings. USE FOR: adopting NRTs in existing codebases, file-by-file or project-wide migration, fixing CS8602/CS8618/CS86xx warnings, annotating APIs for nullability, cleaning up null-forgiving operators, upgrading dependencies with new nullable annotations. DO NOT USE FOR: projects already fully migrated with zero warnings (unless auditing suppressions), fixing a handful of nullable warnings in code that already has NRTs enabled, suppressing warnings without fixing them, C# 7.3 or earlier projects. INVOKES: Get-Nul
repo: dotnet/skills
Popularité
- Étoiles GitHub
- 5.8k
- Position au classement
- #14648
- Licence
- MIT
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
create-custom-agent
5.8kAide votre agent à créer des fichiers d'agents personnalisés pour VS Code, avec leurs propres outils, instructions et transferts vers d'autres agents.
create-skill
5.8kAide votre agent à créer une nouvelle skill d'agent avec un nom valide, une description de déclenchement claire et un fichier SKILL.md conforme à la norme.
csharp-scripts
5.8kAide votre agent à exécuter un petit programme C# en un seul fichier avec l'outil en ligne de commande .NET, sans créer de projet complet.
dotnet-pinvoke
5.8kAide votre agent à appeler correctement des bibliothèques natives C ou C++ depuis .NET, en couvrant les signatures, la gestion des chaînes, la mémoire et les handles sûrs.
Skills similaires
diffs
394kPermet à votre agent de produire un diff réel et partageable de vos modifications, sous forme de lien ou d'image, plutôt qu'un résumé écrit à la main.
coding-agent
394kAide votre agent à confier une tâche de programmation plus importante à Codex, Claude Code ou OpenCode comme travailleur en arrière-plan, puis à suivre sa progression.
gh-issues
394kAide votre agent à trouver des tickets GitHub, choisir ceux à traiter et ouvrir des pull requests avec des correctifs, y compris le suivi des commentaires de relecture.