Repository navigation
Enabling nullability in NuGet.Packaging - Package Creation - #7217
Merged
Merged
Conversation
jeffkl
reviewed
Mar 17, 2026
nkolev92
force-pushed
the
dev-nkolev92-packaging-phase-4
branch
from
March 17, 2026 18:11
f842484 to
a0cce42
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR continues the NuGet.Packaging nullability enablement work by updating package-creation and related packaging/signing APIs to be nullable-annotated, adjusting implementations to satisfy the new contracts, and updating PublicAPI listings accordingly.
Changes:
- Removed
#nullable disableacross package creation/signing/rules code and annotated APIs with?, attributes, and null-suppression where needed. - Introduced stricter construction contracts via
requiredon select model properties. - Updated PublicAPI shipped/unshipped files for net472/net8.0 and adjusted/added a few call sites/tests for the new nullability behavior.
Reviewed changes
Copilot reviewed 51 out of 51 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| test/NuGet.Core.Tests/NuGet.Packaging.Test/SigningTests/RepositorySignatureInfoUtilityTests.cs | Updates tests to pass empty certificate list instead of null. |
| src/NuGet.Core/NuGet.Packaging/Signing/SignatureLog.cs | Enables nullability and updates Equals signature/nullable properties. |
| src/NuGet.Core/NuGet.Packaging/Signing/SignatureException.cs | Enables nullability and marks optional properties nullable. |
| src/NuGet.Core/NuGet.Packaging/Signing/RepositorySignatureInfoProvider.cs | Adds nullability annotations to TryGet... out parameter with [NotNullWhen]. |
| src/NuGet.Core/NuGet.Packaging/Signing/RepositorySignatureInfo.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Signing/Oids.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Rules/UpholdBuildConventionRule.cs | Nullability updates in rule implementation and comparer. |
| src/NuGet.Core/NuGet.Packaging/Rules/UnspecifiedDependencyVersionRule.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Rules/RuleSet.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Rules/ReferencesInNuspecMatchRefAssetsRule.cs | Adds null-safety (!/?) around XML traversal and collections. |
| src/NuGet.Core/NuGet.Packaging/Rules/PathTooLongRule.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Rules/MisplacedAssemblyUnderLibRule.cs | Nullability updates around path handling. |
| src/NuGet.Core/NuGet.Packaging/Rules/LicenseUrlDeprecationWarning.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Rules/InvalidUndottedFrameworkRule.cs | Adds null-safety to XML traversal and property extraction. |
| src/NuGet.Core/NuGet.Packaging/Rules/InvalidPrereleaseDependencyRule.cs | Tightens Validate to treat builder as non-null. |
| src/NuGet.Core/NuGet.Packaging/Rules/InvalidPlaceholderFileRule.cs | Nullability updates around path handling. |
| src/NuGet.Core/NuGet.Packaging/Rules/InitScriptNotUnderToolsRule.cs | Nullability updates around path handling. |
| src/NuGet.Core/NuGet.Packaging/Rules/IconUrlDeprecationWarning.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/Rules/DependenciesGroupsForEachTFMRule.cs | Adds null-safety around XML root usage. |
| src/NuGet.Core/NuGet.Packaging/Rules/DefaultManifestValuesRule.cs | Adds null-suppression when emitting warnings. |
| src/NuGet.Core/NuGet.Packaging/PublicAPI/net8.0/PublicAPI.Unshipped.txt | Updates unshipped API entries to reflect nullable annotations. |
| src/NuGet.Core/NuGet.Packaging/PublicAPI/net8.0/PublicAPI.Shipped.txt | Updates shipped API entries to reflect nullable annotations. |
| src/NuGet.Core/NuGet.Packaging/PublicAPI/net472/PublicAPI.Unshipped.txt | Updates unshipped API entries to reflect nullable annotations. |
| src/NuGet.Core/NuGet.Packaging/PublicAPI/net472/PublicAPI.Shipped.txt | Updates shipped API entries to reflect nullable annotations. |
| src/NuGet.Core/NuGet.Packaging/PackageExtractor.cs | Updates call site to match new nullability of repository signature APIs. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Xml/PackageMetadataXmlExtensions.cs | Nullability updates and safer attribute construction when writing nuspec XML. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Utility/PackageIdValidator.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Utility/FrameworkNameUtility.cs | Makes framework parsing APIs nullable and applies null-suppression for directory parsing. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/XElementExtensions.cs | Enables nullability and adjusts signatures to allow nullable inputs/outputs. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/StringExtensions.cs | Enables nullability and marks legacy helper as obsolete. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/FrameworksExtensions.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Extensions/CollectionExtensions.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PhysicalPackageFile.cs | Introduces nullable/required changes and converts framework fields to auto-properties. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageReferenceSet.cs | Enables nullability for target framework and related constructors. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/PackageBuilder.cs | Broad nullability enablement across package creation APIs and internal helpers. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestVersionUtility.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestSchemaUtility.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestReader.cs | Enables nullability and adjusts XML parsing and model population accordingly. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestMetadata.cs | Enables nullability and adjusts validation/merge logic accordingly. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestFile.cs | Enables nullability for file entries and validation. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/ManifestContentFiles.cs | Makes Include required and enables nullability on optional fields. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/Manifest.cs | Enables nullability and adjusts file list handling. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/LicenseMetadata.cs | Makes LicenseUrl non-null and updates behavior for unsupported license types. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/IPackageMetadata.cs | Updates metadata interface to nullable where appropriate. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/IPackageFile.cs | Updates file interface to nullable for framework/effective path where appropriate. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/FrameworkAssemblyReference.cs | Removes #nullable disable as part of nullability enablement. |
| src/NuGet.Core/NuGet.Packaging/PackageCreation/Authoring/EmptyFrameworkFolderFile.cs | Adds [SetsRequiredMembers] to align with required base members. |
| src/NuGet.Core/NuGet.Packaging/NuspecReader.cs | Removes SafeTrim usage and aligns license parsing with nullability. |
| src/NuGet.Core/NuGet.Packaging/NupkgMetadata/NupkgMetadataFile.cs | Introduces required on ContentHash and enables nullability. |
| src/NuGet.Core/NuGet.Packaging/Core/PackageIdentity.cs | Adds NU_NULL_INC marker to intentional nullable-contract mismatch. |
| src/NuGet.Core/NuGet.Commands/RestoreCommand/DependencyGraphResolver.cs | Adds null-guard when aggregating suppressions. |
Comments suppressed due to low confidence (1)
src/NuGet.Core/NuGet.Packaging/Rules/MisplacedAssemblyUnderLibRule.cs:29
Path.GetDirectoryName(file)can returnnullwhenfileis at the package root (e.g.readme.txt). The null-forgiving operator here will lead to aNullReferenceExceptionwhen callingdirectory.Equals(...). Consider usingvar directory = Path.GetDirectoryName(file) ?? string.Empty;(or skipping files with no directory).
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
zivkan
approved these changes
Mar 18, 2026
jeffkl
approved these changes
Mar 18, 2026
Nigusu-Allehu
approved these changes
Mar 18, 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
Continuation of #7210.
These changes cover all the packaging creation APIs.
This is the most complex PR to date in the nullability enabling.
There are a bunch of places where we'll better off purposely annotating incorrectly, so I'm adding a keyword to help find those instances,
NU_NULL_INC.Note that this is ok and intentional as implementers can have stricter nullability restrictions.
requiredto the properties in types where it'd be helpful to enforce non-nullability such as ManifestContentFiles.Include.After this, signing APIs are the only thing that's left.
PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.