Skip to content

Warn when adding non-compliant package IDs - #7704

Merged
nkolev92 merged 1 commit into
devfrom
dev-nkolev92-warnNonCompliantPackageId
Sep 16, 2026
Merged

nkolev92 merged 1 commit into
devfrom
dev-nkolev92-warnNonCompliantPackageId

Conversation

@nkolev92

Copy link
Copy Markdown
Member

Bug

Fixes: NuGet/Home#15076

Description

Adds a non-blocking warning when dotnet package add (or its dotnet add package alias) successfully adds a directly requested package whose ID does not meet NuGet's restricted package-ID rules. This warns customers before they adopt a package ID that no longer meets NuGet's package-ID standard while preserving support for consuming existing legacy packages.

This is a command-specific extension of the accepted package-ID design, which introduced the corresponding pack warning following NuGet/Announcements#75. It does not introduce a new validation policy.

Functional behavior

Compliant package IDs preserve the current output:

dotnet package add Contoso.Utilities

A successfully added non-compliant direct package ID produces one warning:

dotnet package add Contöso.Utilities
warn : The package ID 'Contöso.Utilities' does not meet NuGet package ID standards. Package IDs must be no more than 100 characters, start with a letter, digit, or underscore, and contain only ASCII letters, digits, dots (.), dashes (-), and underscores (_). Dots and dashes cannot appear consecutively or at the end.

The warning is emitted for the package ID supplied by the user only; the dependency graph is not scanned, so non-compliant transitive package IDs do not warn. Both command spellings use the same XPlat runner and therefore have identical behavior.

Implementation decisions

  • Reuses PackageIdValidator.IsValidPackageId(packageId, useRestrictedCharacterSet: true) so add-package and pack remain aligned on the validation rules.
  • Logs through ILogger.LogWarning(string) without a NuGetLogCode. The warning cannot be suppressed through NoWarn, promoted through WarningsAsErrors, or converted to an error by TreatWarningsAsErrors.
  • Emits the warning once, after the project update and restore commit succeed. The --no-restore path emits it after the package reference is written. Failed resolution, compatibility checks, project updates, and restore commits do not produce a misleading warning.
  • Does not gate the warning on SdkAnalysisLevel. This is advisory interactive CLI output that cannot fail the operation, and gating --no-restore would require loading the dependency graph on its current fast path solely to obtain SDK metadata.

Testing

Adds unit coverage for compliant, non-ASCII, homoglyph, Japanese, trailing-separator, and package-ID length cases. Functional coverage verifies the --no-restore path, direct-versus-transitive scope, suppression on failed adds, and successful project updates when TreatWarningsAsErrors is enabled.

Out of scope

Restore-time or transitive dependency warnings, changing pack warning NU5052, blocking package consumption, warning suppression, Visual Studio or Package Manager Console behavior, and dotnet package update.

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 marked this pull request as ready for review September 15, 2026 18:24
@nkolev92
nkolev92 requested a review from a team as a code owner September 15, 2026 18:24
@nkolev92

Copy link
Copy Markdown
Member Author

cc @baronfel @JonDouglas

@nkolev92
nkolev92 merged commit 6bee687 into dev Sep 16, 2026
18 checks passed
@nkolev92
nkolev92 deleted the dev-nkolev92-warnNonCompliantPackageId branch September 16, 2026 14: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.

Add a non breaking warning in dotnet add package when non compliant package ids are used

5 participants