Nullable annotations for most of NuGet.ProjectModel#7172
Conversation
There was a problem hiding this comment.
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 disabledirectives 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 |
|
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. |
|
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. |
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
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.