Skip to content

Commit cddfada

Browse files
nkolev92Copilot
andcommitted
Scope NU5052 warning to SDK projects only
Only emit the restricted package ID warning (NU5052) when UsingMicrosoftNETSdk is true. Non-SDK projects (nuget.exe pack) do not emit this warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c63de02 commit cddfada

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/NuGet.Core/NuGet.Commands/CommandRunners/PackCommandRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private bool BuildPackage(PackageBuilder builder, string outputPath = null, bool
117117
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
118118

119119
// Warn if the package ID doesn't adhere to the restricted character set (NU5052)
120-
if (!symbolsPackage && !PackageIdValidator.IsValidPackageId(builder.Id, useRestrictedCharacterSet: true))
120+
if (!symbolsPackage && _packArgs.UsingMicrosoftNETSdk && !PackageIdValidator.IsValidPackageId(builder.Id, useRestrictedCharacterSet: true))
121121
{
122122
if (SdkAnalysisLevelMinimums.IsEnabled(_packArgs.SdkAnalysisLevel, _packArgs.UsingMicrosoftNETSdk, SdkAnalysisLevelMinimums.V11_0_100))
123123
{

test/NuGet.Core.Tests/NuGet.Commands.Test/PackCommandRunnerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void Dispose()
264264
[InlineData("Contöso.Utilities", "11.0.100", true, true)] // non-ASCII ö, enabled → emits
265265
[InlineData("\u0421ontoso.Utilities", "11.0.100", true, true)] // Cyrillic С, enabled → emits
266266
[InlineData("Contöso.Utilities", "10.0.100", true, false)] // below threshold → suppressed
267-
[InlineData("Contöso.Utilities", null, false, true)] // non-SDK project (nuget.exe) → emits
267+
[InlineData("Contöso.Utilities", null, false, false)] // non-SDK project (nuget.exe) → not emitted (SDK-only warning)
268268
[InlineData("Contöso.Utilities", null, true, false)] // SDK project, no level (assumes 8.0.400) → suppressed
269269
public void BuildPackage_PackageIdWithInvalidCharacters_EmitsNU5052_BasedOnSdkAnalysisLevel(string packageId, string? sdkAnalysisLevel, bool usingMicrosoftNETSdk, bool expectWarning)
270270
{

0 commit comments

Comments
 (0)