Make nullable enabled by default across entire repo - #6960
#6960Merged
zivkan merged 4 commits intoNov 20, 2025
devNuGet/NuGet.Client:devfrom
dev-zivkan-nullable-defaultNuGet/NuGet.Client:dev-zivkan-nullable-defaultCopy head branch name to clipboard
Merged
Make nullable enabled by default across entire repo#6960zivkan merged 4 commits intodevNuGet/NuGet.Client:devfrom dev-zivkan-nullable-defaultNuGet/NuGet.Client:dev-zivkan-nullable-defaultCopy head branch name to clipboard
zivkan merged 4 commits into
devNuGet/NuGet.Client:devfrom
dev-zivkan-nullable-defaultNuGet/NuGet.Client:dev-zivkan-nullable-defaultCopy head branch name to clipboard
Conversation
…ave to special case the project
jeffkl
reviewed
Nov 19, 2025
jeffkl
left a comment
Contributor
There was a problem hiding this comment.
Let's make sure all of the #nullable enable are removed
Member
Author
As I wrote in the PR description, since NuGet.CommandLine.XPlat uses a package that ships source code, and that code doesn't work when nullable is enabled, I had to disable nullable by default in the project and enable it in individual files used by the project. |
Nigusu-Allehu
approved these changes
Nov 20, 2025
nkolev92
approved these changes
Nov 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: code quality
Description
Enable C# nullable annotation checking across entire repo in 3 easy steps:
<Nullable>enable</Nullable>in build/common.project.props#nullable disableto every.csfile that fails to compile, until the solution compiles again.#nullable enablefrom all the code that previously opt-in individually.#nullable enablewhere possible. We need to migrate the CLI parser to System.CommandLine and remove the other package to bring this project back in line with the rest of the repo.Step 2 was performed by creating an MSBuild logger that logged every message to JSON, then doing command line builds using the custom logger. Then a second app was used to parse the json output, find files that are failing to compile, then add
#nullable disableto the top of the file. Then, I just needed to keep running the two commands in a loop, with only a few manual fixes, to get the repo building again.Step 3 was mostly a global search and replace, but it did find a few places where nullable was disabled and then re-enabled in the same file, so those were cleaned up.
Personally, I find the easiest way to review this PR is to do
git diff origin/dev...on the command line. Then page through the results. The vast majority of changes are#nullablelines, so you can quickly scroll and anything that's different really pops out for more detailed investigation.Doing
git diff origin/dev... --statshows the number of lines changed per file, and almost all files only have one or two lines changed. The files with more than 2 lines changed are:Doing
(gci -recurse -filter *.cs).Lengthin PowerShell after a git clean shows there are 3882.csfiles in the repo. Since this PR changes 2176, and some of those are csproj files, and about 300 were files with#nullable enableremoved, I estimate about 2,000 files now have null checking enabled, which is a little over half the files. It's also easy for someone enthusiastic about making more nullability improvements, as they can search for#nullable disableand start fixing some files.PR Checklist
and a linked NuGet/Home issueAdded testsN/ALink to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.N/A