Enabling nullability in NuGet.Packaging - phase 1, models and simple classes#7176
Merged
Enabling nullability in NuGet.Packaging - phase 1, models and simple classes#7176
Conversation
zivkan
approved these changes
Feb 27, 2026
Member
zivkan
left a comment
There was a problem hiding this comment.
The title of this PR doesn't make sense before reading the linked issue. Please update it, and try to remember to change the title of the squash commit when merging the PR.
Member
Author
|
I meant to fix this but I forgot. Thanks for the reminder . |
Nigusu-Allehu
approved these changes
Feb 27, 2026
3 tasks
This was referenced Mar 10, 2026
This was referenced Mar 12, 2026
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
Progress: NuGet/Home#14778
Description
Similar to #7172.
Enable nullability in NuGet.Packaging.
This is by far the most challenging, because certain types such as PackageIdentity are kind of broken by allowing nullable version.
This first PR enables nullability in mostly models, primarily focusing on leaf types and simpler types.
It's really a pretty inconsequential PR in terms of the grand scheme of things since there's really no actual code changes based on the learnings from the annotations.
There is only really 1 questionable change.
PackageIdentity.Version is being annotated as not nullable despite it being nullable.
PackageIdentity with a null version is used in 3 places in our code, in the packages.config resolver, and to pass an uninstallation request sometimes in the nuget package manager.
Many, many places use PackageIdentity.Version blindly without null checks, but in those scenarios null is not even possible.
It's a really bad decision to have the Version be nullable, but changing that would be binary breaking change on a pretty core type. Not to mention runs the risk of actual regressions.
When I annotated it as null, copilot made changes in 200+ files to address nullability warnings. And that doesn't even consider the fact that majority of the places where this type is used, are actually not null aware yet.
After a chat with @zivkan who's looked into this before, we just think incorrectly annotating is the better solution.
There'll be some follow-up work to add more nullability in this class, but I want to minimize risk and make it easier to review.
PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.