From 2b8b231560fa90069d0ca739104d5177d12cd22d Mon Sep 17 00:00:00 2001 From: ZhaoMCX <78784728+ZhaoMCX@users.noreply.github.com> Date: Wed, 29 Jul 2026 15:39:50 +0800 Subject: [PATCH] fix: skip code fix assemblies when configuring Roslyn analyzers --- .../Assets/Tests/Editor/NuGetTests.cs | 7 +++++++ src/NuGetForUnity/Editor/Helper/AnalyzerHelper.cs | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/NuGetForUnity.Tests/Assets/Tests/Editor/NuGetTests.cs b/src/NuGetForUnity.Tests/Assets/Tests/Editor/NuGetTests.cs index 33680a7e..5cdc34af 100644 --- a/src/NuGetForUnity.Tests/Assets/Tests/Editor/NuGetTests.cs +++ b/src/NuGetForUnity.Tests/Assets/Tests/Editor/NuGetTests.cs @@ -52,6 +52,13 @@ public void SimpleRestoreTest() Assert.Pass(); } + [TestCase("MessagePack.Analyzers.CodeFixes.dll")] + [TestCase("messagepack.analyzers.codefixes.DLL")] + public void CodeFixAssemblyIsNotEnabledAsRoslynAnalyzerTest(string assemblyPath) + { + Assert.IsFalse(AnalyzerHelper.ShouldEnableRoslynAnalyzer(assemblyPath)); + } + [Test] public void LoadConfigFileTest() { diff --git a/src/NuGetForUnity/Editor/Helper/AnalyzerHelper.cs b/src/NuGetForUnity/Editor/Helper/AnalyzerHelper.cs index ac4a143d..a60f55e8 100644 --- a/src/NuGetForUnity/Editor/Helper/AnalyzerHelper.cs +++ b/src/NuGetForUnity/Editor/Helper/AnalyzerHelper.cs @@ -16,6 +16,11 @@ internal static class AnalyzerHelper /// private const string AnalyzersFolderName = "analyzers"; + /// + /// File name suffix used by assemblies that provide IDE code fixes instead of compiler analyzers. + /// + private const string CodeFixAssemblySuffix = ".CodeFixes.dll"; + /// /// Name of the root folder containing dotnet analyzers. /// @@ -33,6 +38,11 @@ internal static class AnalyzerHelper /// True if the label should be added, false otherwise. public static bool ShouldEnableRoslynAnalyzer(string path) { + if (path.EndsWith(CodeFixAssemblySuffix, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + // The nuget package can contain analyzers for multiple Roslyn versions. // In that case, for the same package, the most recent version must be chosen out of those available for the current Unity version. var assetPath = Path.GetFullPath(path);