From 20b61119b8a869efb82221f4a705ec09fcd69b5f Mon Sep 17 00:00:00 2001 From: "Brett V. Forsgren" Date: Mon, 18 May 2026 12:00:16 -0600 Subject: [PATCH] Detect NoWarn NU1701 in SDK project discovery and warn during report Add HasNoWarnNU1701 property to ProjectDiscoveryResult that is set during SDK project discovery when the NoWarn property contains NU1701. The warning is reported once per project during ReportDiscovery using a fully normalized rooted path in sorted order. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Utilities/LoggerTests.cs | 44 +++++++++++++++++++ .../Discover/ProjectDiscoveryResult.cs | 1 + .../Discover/SdkProjectDiscovery.cs | 13 ++++++ .../NuGetUpdater.Core/Utilities/ILogger.cs | 10 +++++ 4 files changed, 68 insertions(+) diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LoggerTests.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LoggerTests.cs index 96a3f9bcb97..6b4ef3ef226 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LoggerTests.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LoggerTests.cs @@ -4,6 +4,8 @@ using System.Text; using System.Threading.Tasks; +using NuGetUpdater.Core.Discover; + using Xunit; using Xunit.Sdk; @@ -56,5 +58,47 @@ public void LogRaw_ShouldStreamLogsIndividually() Assert.Contains(testMessage2, output); } + [Fact] + public void ReportDiscovery_LogsWarningForProjectsWithNU1701() + { + var logger = new StringLogger(); + var discoveryResult = new WorkspaceDiscoveryResult() + { + Path = "/src", + Projects = [ + new() + { + FilePath = "zebra.csproj", + Dependencies = [], + ImportedFiles = [], + AdditionalFiles = [], + HasNoWarnNU1701 = true, + }, + new() + { + FilePath = "middle.csproj", + Dependencies = [], + ImportedFiles = [], + AdditionalFiles = [], + HasNoWarnNU1701 = false, + }, + new() + { + FilePath = "alpha.csproj", + Dependencies = [], + ImportedFiles = [], + AdditionalFiles = [], + HasNoWarnNU1701 = true, + }, + ] + }; + + logger.ReportDiscovery(discoveryResult); + var warnings = logger.Messages.Where(m => m.Contains("has NoWarn property containing NU1701; package compatibility checks may be inaccurate.")).ToList(); + Assert.Equal(2, warnings.Count); + Assert.Contains("/src/alpha.csproj", warnings[0]); + Assert.Contains("/src/zebra.csproj", warnings[1]); + Assert.DoesNotContain(logger.Messages, m => m.Contains("Project [/src/middle.csproj] has NoWarn property containing NU1701; package compatibility checks may be inaccurate.")); + } } diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs index f3d8d26dabe..28ef30c05cc 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs @@ -16,4 +16,5 @@ public record ProjectDiscoveryResult : IDiscoveryResultWithDependencies public required ImmutableArray ImportedFiles { get; init; } public required ImmutableArray AdditionalFiles { get; init; } public required ImmutableArray Dependencies { get; init; } + public bool HasNoWarnNU1701 { get; init; } = false; } diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs index c204685878d..8156396d3f9 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs @@ -674,6 +674,18 @@ PackageManagementKind.CentralPackageManagement or packageManagementKind = PackageManagementKind.Default; } + // check for NoWarn containing NU1701 + var noWarnValue = GetStringPropertyFromProjectProperties(projectProperties, "NoWarn"); + var hasNoWarnNU1701 = false; + if (noWarnValue is not null) + { + var noWarnCodes = noWarnValue.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + if (noWarnCodes.Contains("NU1701", StringComparer.OrdinalIgnoreCase)) + { + hasNoWarnNU1701 = true; + } + } + var projectDiscoveryResult = new ProjectDiscoveryResult() { FilePath = projectRelativePath, @@ -684,6 +696,7 @@ PackageManagementKind.CentralPackageManagement or AdditionalFiles = additional, PackageManagementKind = packageManagementKind, PackageManagementSpecialFileRelativePath = packageManagementFile, + HasNoWarnNU1701 = hasNoWarnNU1701, }; projectDiscoveryResults.Add(projectDiscoveryResult); } diff --git a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs index 9a5e5ba625b..c4fafa783f4 100644 --- a/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs +++ b/nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs @@ -24,6 +24,16 @@ public static void ReportAnalysis(this ILogger logger, AnalysisResult analysisRe public static void ReportDiscovery(this ILogger logger, WorkspaceDiscoveryResult discoveryResult) { + var nu1701Projects = discoveryResult.Projects + .Where(p => p.HasNoWarnNU1701) + .Select(p => PathHelper.JoinPath(discoveryResult.Path, p.FilePath).FullyNormalizedRootedPath()) + .OrderBy(p => p, StringComparer.OrdinalIgnoreCase) + .ToList(); + foreach (var projectPath in nu1701Projects) + { + logger.Warn($"Project [{projectPath}] has NoWarn property containing NU1701; package compatibility checks may be inaccurate."); + } + logger.Info("Discovery JSON content:"); logger.Info(JsonSerializer.Serialize(discoveryResult, DiscoveryWorker.SerializerOptions)); }