Skip to content

Nullable annotations for most of NuGet.ProjectModel#7172

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

Nullable annotations for most of NuGet.ProjectModel#7172
nkolev92 merged 4 commits intodevfrom
dev-nkolev92-projectmodelnullable

Conversation

@nkolev92
Copy link
Copy Markdown
Member

@nkolev92 nkolev92 commented Feb 25, 2026

Bug

Progress: NuGet/Home#14779

Description

Add nullable annotations for a bunch of NuGet.ProjectModel.
This is something that we'll be doing incrementally.
I used copilot cli to do most of this work before realizing I should've had it start with NuGet.Packaging, but that one is a beast :D

So yeah this is good progress.

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 added Engineering Changes related to the build infrastructure of the repo and that do not change product code and removed Engineering Changes related to the build infrastructure of the repo and that do not change product code labels Feb 27, 2026
@nkolev92 nkolev92 marked this pull request as ready for review February 27, 2026 00:00
@nkolev92 nkolev92 requested a review from a team as a code owner February 27, 2026 00:00
@jeffkl jeffkl requested a review from Copilot February 27, 2026 17:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds nullable reference type annotations to most of the NuGet.ProjectModel assembly. The changes systematically remove #nullable disable directives from source files and add appropriate nullable annotations to parameters, return types, and properties throughout the codebase.

Changes:

  • Removed #nullable disable directives from source files in NuGet.ProjectModel
  • Added nullable annotations (?) to parameters, properties, and return types where appropriate
  • Added null-forgiving operators (!) in test files to assert non-null values in test scenarios
  • Updated PublicAPI.Shipped.txt to reflect new nullable annotations
  • Added obsolete attributes to unused APIs (JTokenExtensions, IExternalProjectReferenceProvider)
  • Updated MsBuildStringUtility.GetNuGetLogCodes to accept nullable string parameter
  • Updated copilot-instructions.md to document nullable reference types being enabled project-wide

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
CentralTransitiveDependencyGroupTests.cs Added null-forgiving operators to test assertions that intentionally pass null values
WarningPropertiesTests.cs Added null-forgiving operators to test assertions for null argument validation
DotnetCliToolTests.cs Added null-forgiving operator when accessing MinVersion property known to be non-null
WarningProperties.cs Removed #nullable disable, added nullable annotations to Equals methods and GetWarningProperties parameters
ToolPathResolver.cs Removed #nullable disable, added null check in constructor, marked GetBestToolDirectoryPath return as nullable
RestoreLockProperties.cs Removed #nullable disable, added nullable annotations to properties and Equals methods
ProjectRestoreSettings.cs Removed #nullable disable, added nullable annotation to SdkVersion property and Equals methods
ProjectRestoreMetadataFile.cs Removed #nullable disable, added nullable annotations to Equals and CompareTo methods
ProjectFileDependencyGroup.cs Removed #nullable disable, added null checks in constructor, nullable annotations to Equals methods
PackagesConfigProjectRestoreMetadata.cs Removed #nullable disable, added nullable annotations to properties and Equals methods, added null check
PackageSpecUtility.cs Removed #nullable disable, added nullable annotations, simplified TryParse with discard operator
JTokenExtensions.cs Removed #nullable disable, added Obsolete attribute, added nullable annotations to return types
IExternalProjectReferenceProvider.cs Removed #nullable disable, added Obsolete attribute
HashObjectWriter.cs Removed #nullable disable, added nullable annotations to event handler and WriteNameValue method
FileFormatException.cs Removed #nullable disable, added nullable annotation to Path property
CircularMemoryStream.cs Removed #nullable disable, added nullable annotation to OnFlush event
CentralTransitiveDependencyGroup.cs Removed #nullable disable, added nullable annotations to Equals methods
PublicAPI.Shipped.txt Updated API signatures to reflect nullable annotations throughout public APIs
MsBuildStringUtility.cs Added nullable annotation to GetNuGetLogCodes parameter
PublicAPI.Shipped.txt (NuGet.Common) Updated GetNuGetLogCodes signature to accept nullable string
.github/copilot-instructions.md Added documentation about project-wide nullable reference types being enabled

Comment thread src/NuGet.Core/NuGet.ProjectModel/ProjectRestoreMetadataFile.cs
@zivkan
Copy link
Copy Markdown
Member

zivkan commented Feb 27, 2026

These changes will affect anyone using the package and having nullable enabled in their own projects, so consider a publlic issue that we can put in the release notes.

@nkolev92
Copy link
Copy Markdown
Member Author

Yep, will create one.

It is very likely not all annotations will be completed, so the issue won't be closed, so we'll have to pay attention to that during the release notes.

@nkolev92 nkolev92 merged commit 1158132 into dev Feb 27, 2026
21 checks passed
@nkolev92 nkolev92 deleted the dev-nkolev92-projectmodelnullable branch February 27, 2026 22:58
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.

4 participants