Skip to content

Enabling nullability in NuGet.Packaging - phase 1, models and simple classes#7176

Merged
nkolev92 merged 4 commits intodevfrom
dev-nkolev92-packaging-nullable
Feb 27, 2026
Merged

Enabling nullability in NuGet.Packaging - phase 1, models and simple classes#7176
nkolev92 merged 4 commits intodevfrom
dev-nkolev92-packaging-nullable

Conversation

@nkolev92
Copy link
Copy Markdown
Member

@nkolev92 nkolev92 commented Feb 27, 2026

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

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@nkolev92 nkolev92 requested a review from zivkan February 27, 2026 18:39
@nkolev92 nkolev92 marked this pull request as ready for review February 27, 2026 18:39
@nkolev92 nkolev92 requested a review from a team as a code owner February 27, 2026 18:39
Copy link
Copy Markdown
Member

@zivkan zivkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nkolev92 nkolev92 changed the title Phase 1, simple classes Enabling nullability in NuGet.Packaging - phase 1, models and simple classes Feb 27, 2026
@nkolev92
Copy link
Copy Markdown
Member Author

I meant to fix this but I forgot. Thanks for the reminder .

Comment thread src/NuGet.Core/NuGet.Packaging/Core/PackageIdentity.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants