From 0c3f6a987e2c45fc460892b3b532738d74c41758 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:02:47 +0200 Subject: [PATCH 1/7] Fix PropertiesUsageCheck reading BC0202 config from BC0201's rule id Initialize() looked up the configuration for the 'property initialized after it was used' rule (BC0202) using the rule id of the 'usage of undefined property' rule (BC0201). Because the same id was queried twice, BC0202 inherited BC0201's configuration: setting BC0201.Severity=none in .editorconfig silently disabled BC0202 as well, even though the two are independently configurable rules that merely share one check implementation. Add an end-to-end regression test asserting the two rules can be configured independently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 776edd7b-5993-4235-bc51-ecb150798083 --- .../BuildCheck/Checks/PropertiesUsageCheck.cs | 2 +- src/BuildCheck.UnitTests/EndToEndTests.cs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Build/BuildCheck/Checks/PropertiesUsageCheck.cs b/src/Build/BuildCheck/Checks/PropertiesUsageCheck.cs index 4223747f472..52745d18708 100644 --- a/src/Build/BuildCheck/Checks/PropertiesUsageCheck.cs +++ b/src/Build/BuildCheck/Checks/PropertiesUsageCheck.cs @@ -58,7 +58,7 @@ public override void Initialize(ConfigurationContext configurationContext) _unusedPropertyEnabled = config.IsEnabled; _unusedPropertyScope = config.EvaluationCheckScope; - config = configurationContext.CheckConfig.FirstOrDefault(c => c.RuleId == _usedBeforeInitializedRule.Id) + config = configurationContext.CheckConfig.FirstOrDefault(c => c.RuleId == _initializedAfterUsedRule.Id) ?? CheckConfigurationEffective.Default; _initializedAfterUseEnabled = config.IsEnabled; diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs index af7e001ad00..f4ae3526df3 100644 --- a/src/BuildCheck.UnitTests/EndToEndTests.cs +++ b/src/BuildCheck.UnitTests/EndToEndTests.cs @@ -66,6 +66,31 @@ public void PropertiesUsageAnalyzerTest(bool buildInOutOfProcessNode) Regex.Matches(output, "BC0203 .* Property").Count.ShouldBe(2); } + [Fact] + public void PropertiesUsageCheck_RulesAreIndependentlyConfigurable() + { + PrepareSampleProjectsAndConfig( + buildInOutOfProcessNode: false, + out TransientTestFile projectFile, + out TransientTestFile editorconfigFile, + "PropsCheckTest.csproj"); + + // Turning BC0201 off must not turn BC0202 off - they are separately configurable rules + // that happen to be implemented by a single check. + File.WriteAllText( + editorconfigFile.Path, + File.ReadAllText(editorconfigFile.Path) + .Replace("build_check.BC0201.Severity=warning", "build_check.BC0201.Severity=none")); + + string output = RunnerUtilities.ExecBootstrapedMSBuild($"{projectFile.Path} -check", out bool success, timeoutMilliseconds: timeoutInMilliseconds); + _env.Output.WriteLine(output); + _env.Output.WriteLine("========================="); + success.ShouldBeTrue(output); + + output.ShouldNotContain("BC0201"); + output.ShouldMatch(@"BC0202: .* Property: 'MyPropT2'"); + } + [Theory] // The culture is not set explicitly, but the extension is a known culture // - a buildcheck warning will occur, but otherwise works From 97944cf29a9f4e95fa7cfd9c6aa0ed27a71c0e5a Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:02:47 +0200 Subject: [PATCH 2/7] Match the Exec task name case-insensitively in ExecCliBuildCheck TaskStartedEventArgs.TaskName is the task element name as authored in the project, so it carries whatever casing the author used, while TaskRegistry resolves task names case-insensitively. An ordinal comparison against 'Exec' therefore skipped the check for invocations such as , which build and run perfectly well. Use MSBuildNameIgnoreCaseComparer, and cover the casing variants plus a negative case in the tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 776edd7b-5993-4235-bc51-ecb150798083 --- .../BuildCheck/Checks/ExecCliBuildCheck.cs | 5 +++- .../ExecCliBuildCheck_Tests.cs | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs b/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs index 252159162b2..b61e5fac851 100644 --- a/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs +++ b/src/Build/BuildCheck/Checks/ExecCliBuildCheck.cs @@ -6,6 +6,7 @@ #if !FEATURE_MSIOREDIST using System.IO; #endif +using Microsoft.Build.Collections; using Microsoft.Build.Shared; #if FEATURE_MSIOREDIST @@ -61,7 +62,9 @@ public override void RegisterActions(IBuildCheckRegistrationContext registration private static void TaskInvocationAction(BuildCheckDataContext context) { - if (context.Data.TaskName == ExecTaskName + // Task names are matched case-insensitively - MSBuild resolves task names without regard to casing, + // so the logged name carries whatever casing the project author used. + if (MSBuildNameIgnoreCaseComparer.Default.Equals(context.Data.TaskName, ExecTaskName) && context.Data.Parameters.TryGetValue(CommandParameterName, out TaskInvocationCheckData.TaskParameter? commandArgument)) { var execCommandValue = commandArgument.Value?.ToString() ?? string.Empty; diff --git a/src/BuildCheck.UnitTests/ExecCliBuildCheck_Tests.cs b/src/BuildCheck.UnitTests/ExecCliBuildCheck_Tests.cs index 105ba97f9e1..acc6ab4bdc7 100644 --- a/src/BuildCheck.UnitTests/ExecCliBuildCheck_Tests.cs +++ b/src/BuildCheck.UnitTests/ExecCliBuildCheck_Tests.cs @@ -89,6 +89,32 @@ public void ExecTask_WithCommandNotExecutingBuild_ShouldNotShowWarning(string? c _registrationContext.Results.Count.ShouldBe(0); } + [Theory] + [InlineData("Exec")] + [InlineData("exec")] + [InlineData("EXEC")] + public void ExecTask_WithDifferingTaskNameCasing_ShouldShowWarning(string taskName) + { + _registrationContext.TriggerTaskInvocationAction(MakeTaskInvocationData(taskName, new Dictionary + { + { "Command", new TaskInvocationCheckData.TaskParameter("dotnet build", IsOutput: false) }, + })); + + _registrationContext.Results.Count.ShouldBe(1); + _registrationContext.Results[0].CheckRule.Id.ShouldBe("BC0302"); + } + + [Fact] + public void DifferentTask_WithBuildCommand_ShouldNotShowWarning() + { + _registrationContext.TriggerTaskInvocationAction(MakeTaskInvocationData("Message", new Dictionary + { + { "Command", new TaskInvocationCheckData.TaskParameter("dotnet build", IsOutput: false) }, + })); + + _registrationContext.Results.Count.ShouldBe(0); + } + private TaskInvocationCheckData MakeTaskInvocationData(string taskName, Dictionary parameters) { string projectFile = Framework.NativeMethods.IsWindows ? @"C:\fake\project.proj" : "/fake/project.proj"; From 67f5a15fd1f1896bb2351f576d3bdd11aa60a95c Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:02:47 +0200 Subject: [PATCH 3/7] Match task names case-insensitively in DoubleWritesCheck The check switched over context.Data.TaskName using ordinal string comparison, so the compiler and copy tasks went unchecked whenever the project author wrote them with different casing, for example or . Replace the switch with an MSBuildNameIgnoreCaseComparer-based helper and cover the casing variants in the tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 776edd7b-5993-4235-bc51-ecb150798083 --- .../BuildCheck/Checks/DoubleWritesCheck.cs | 19 +++++++++++---- .../DoubleWritesAnalyzer_Tests.cs | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs b/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs index d2320616e71..93683dc7758 100644 --- a/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs +++ b/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs @@ -7,6 +7,7 @@ using System.IO; #endif using System.Linq; +using Microsoft.Build.Collections; using Microsoft.Build.Shared; using static Microsoft.Build.Experimental.BuildCheck.TaskInvocationCheckData; @@ -49,15 +50,23 @@ public override void RegisterActions(IBuildCheckRegistrationContext registration private void TaskInvocationAction(BuildCheckDataContext context) { // This check uses a hard-coded list of tasks known to write files. - switch (context.Data.TaskName) + // Task names are matched case-insensitively - MSBuild resolves task names without regard to casing, + // so the logged name carries whatever casing the project author used. + string taskName = context.Data.TaskName; + + if (IsTask(taskName, "Csc") || IsTask(taskName, "Vbc") || IsTask(taskName, "Fsc")) + { + CheckCompilerTask(context); + } + else if (IsTask(taskName, "Copy")) { - case "Csc": - case "Vbc": - case "Fsc": CheckCompilerTask(context); break; - case "Copy": CheckCopyTask(context); break; + CheckCopyTask(context); } } + private static bool IsTask(string taskName, string expectedTaskName) + => MSBuildNameIgnoreCaseComparer.Default.Equals(taskName, expectedTaskName); + private void CheckCompilerTask(BuildCheckDataContext context) { var taskParameters = context.Data.Parameters; diff --git a/src/BuildCheck.UnitTests/DoubleWritesAnalyzer_Tests.cs b/src/BuildCheck.UnitTests/DoubleWritesAnalyzer_Tests.cs index 29880b5a7f2..9ea70f0a3e7 100644 --- a/src/BuildCheck.UnitTests/DoubleWritesAnalyzer_Tests.cs +++ b/src/BuildCheck.UnitTests/DoubleWritesAnalyzer_Tests.cs @@ -53,10 +53,33 @@ public void TestCopyTask() _registrationContext.Results[0].CheckRule.Id.ShouldBe("BC0102"); } + [Theory] + [InlineData("Copy")] + [InlineData("copy")] + [InlineData("COPY")] + public void TestCopyTask_TaskNameCasingIsIgnored(string taskName) + { + _registrationContext.TriggerTaskInvocationAction(MakeTaskInvocationData(taskName, new Dictionary + { + { "SourceFiles", new TaskInvocationCheckData.TaskParameter("source1", IsOutput: false) }, + { "DestinationFolder", new TaskInvocationCheckData.TaskParameter("outdir", IsOutput: false) }, + })); + _registrationContext.TriggerTaskInvocationAction(MakeTaskInvocationData(taskName, new Dictionary + { + { "SourceFiles", new TaskInvocationCheckData.TaskParameter("source1", IsOutput: false) }, + { "DestinationFiles", new TaskInvocationCheckData.TaskParameter(Path.Combine("outdir", "source1"), IsOutput: false) }, + })); + + _registrationContext.Results.Count.ShouldBe(1); + _registrationContext.Results[0].CheckRule.Id.ShouldBe("BC0102"); + } + [Theory] [InlineData("Csc")] [InlineData("Vbc")] [InlineData("Fsc")] + [InlineData("csc")] + [InlineData("VBC")] public void TestCompilerTask(string taskName) { for (int i = 0; i < 2; i++) From cb7d43067abc66026a9f066838c1dd4cd7ddc7d4 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:02:47 +0200 Subject: [PATCH 4/7] Compare task parameter names case-insensitively in BuildEventsProcessor The dictionary of task parameters handed to checks used the default ordinal comparer. Parameter names are MSBuild names, so look them up with MSBuildNameIgnoreCaseComparer to keep checks insensitive to casing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 776edd7b-5993-4235-bc51-ecb150798083 --- src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs b/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs index 306f8786712..ffda0b5b034 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildEventsProcessor.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Build.Collections; using Microsoft.Build.Construction; using Microsoft.Build.Evaluation; using Microsoft.Build.Framework; @@ -149,7 +150,9 @@ internal void ProcessTaskStartedEventArgs( // Add a new entry to _tasksBeingExecuted. TaskParameters are initialized empty and will be recorded // based on TaskParameterEventArgs we receive later. - Dictionary taskParameters = new(); + // Parameter names are MSBuild names - compare them case-insensitively so checks are not sensitive + // to the casing a project author happened to use. + Dictionary taskParameters = new(MSBuildNameIgnoreCaseComparer.Default); ExecutingTaskData taskData = new() { From d78287b7943810c0b40e08db087c7b4a3586e03b Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:02:48 +0200 Subject: [PATCH 5/7] Document BC0301's default severity as Error Codes.md listed the default severity of BC0301 (building from the Downloads folder) as None. BuildingFromDownloadsFolderCheck declares it as Error, and it does fail the build when triggered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 776edd7b-5993-4235-bc51-ecb150798083 --- documentation/specs/BuildCheck/Codes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/specs/BuildCheck/Codes.md b/documentation/specs/BuildCheck/Codes.md index 1d2faddf3cd..cf18ebcbaa9 100644 --- a/documentation/specs/BuildCheck/Codes.md +++ b/documentation/specs/BuildCheck/Codes.md @@ -15,7 +15,7 @@ Report codes are chosen to conform to suggested guidelines. Those guidelines are | [BC0201](#bc0201---usage-of-undefined-property) | Warning | Project | 9.0.100 | Usage of undefined property. | | [BC0202](#bc0202---property-first-declared-after-it-was-used) | Warning | Project | 9.0.100 | Property first declared after it was used. | | [BC0203](#bc0203----property-declared-but-never-used) | None | Project | 9.0.100 | Property declared but never used. | -| [BC0301](#bc0301---building-from-downloads-folder) | None | Project | 9.0.300 | Building from Downloads folder. | +| [BC0301](#bc0301---building-from-downloads-folder) | Error | Project | 9.0.300 | Building from Downloads folder. | | [BC0302](#bc0302---building-using-the-exec-task) | Warning | N/A | 9.0.300 | Building using the Exec task. | Notes: From ad5452926584a932c21e0cf0a68a5b0076677d68 Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Mon, 24 Aug 2026 15:48:51 +0200 Subject: [PATCH 6/7] Test that task parameter names are matched case-insensitively BuildEventsProcessor now builds the task parameter dictionary with MSBuildNameIgnoreCaseComparer, but nothing covered it: the existing unit tests construct that dictionary themselves with the default ordinal comparer, so reverting the change left the suite green. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5a0ecc6c-d95c-4610-a1a0-44c8bdb5c9d2 --- .../TaskInvocationAnalysisDataTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs b/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs index 12b3f4e3a82..b22405d137e 100644 --- a/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs +++ b/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs @@ -121,6 +121,26 @@ public void ReportsSimpleTaskParameters() data.Parameters["Text"].Value.ShouldBe("Hello"); } + [Theory] + [InlineData("Text")] + [InlineData("text")] + [InlineData("TEXT")] + [InlineData("tExT")] + public void ReportsTaskParametersKeyedCaseInsensitively(string parameterName) + { + BuildProject(""); + + s_testCheck!.CheckData.Count.ShouldBe(1); + var data = s_testCheck.CheckData[0]; + + // Parameter names are MSBuild names, so a check must be able to look them up without + // knowing the casing the task author declared the property with. + data.Parameters.ContainsKey(parameterName).ShouldBeTrue(); + data.Parameters.TryGetValue(parameterName, out var parameter).ShouldBeTrue(); + parameter.ShouldNotBeNull().Value.ShouldBe("Hello"); + data.Parameters[parameterName].Value.ShouldBe("Hello"); + } + [Theory] [InlineData("")] [InlineData("")] From 192ddaeae4d61640d16a1c34a73a66bef7b3e6bb Mon Sep 17 00:00:00 2001 From: AR-May <67507805+AR-May@users.noreply.github.com> Date: Thu, 27 Aug 2026 15:10:36 +0200 Subject: [PATCH 7/7] Match compiler task names with a FrozenSet instead of a helper Addresses PR feedback: drop the IsTask helper and the || chain, and use a FrozenSet keyed by MSBuildNameIgnoreCaseComparer for the hard-coded list of compiler tasks known to write files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Build/BuildCheck/Checks/DoubleWritesCheck.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs b/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs index 93683dc7758..178ce007580 100644 --- a/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs +++ b/src/Build/BuildCheck/Checks/DoubleWritesCheck.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Frozen; using System.Collections.Generic; #if !FEATURE_MSIOREDIST using System.IO; @@ -47,6 +48,11 @@ public override void RegisterActions(IBuildCheckRegistrationContext registration /// private readonly Dictionary _filesWritten = new(StringComparer.CurrentCultureIgnoreCase); + /// + /// Compiler tasks known to write files. + /// + private static readonly FrozenSet s_compilerTaskNames = new[] { "Csc", "Vbc", "Fsc" }.ToFrozenSet(MSBuildNameIgnoreCaseComparer.Default); + private void TaskInvocationAction(BuildCheckDataContext context) { // This check uses a hard-coded list of tasks known to write files. @@ -54,19 +60,16 @@ private void TaskInvocationAction(BuildCheckDataContext // so the logged name carries whatever casing the project author used. string taskName = context.Data.TaskName; - if (IsTask(taskName, "Csc") || IsTask(taskName, "Vbc") || IsTask(taskName, "Fsc")) + if (s_compilerTaskNames.Contains(taskName)) { CheckCompilerTask(context); } - else if (IsTask(taskName, "Copy")) + else if (MSBuildNameIgnoreCaseComparer.Default.Equals(taskName, "Copy")) { CheckCopyTask(context); } } - private static bool IsTask(string taskName, string expectedTaskName) - => MSBuildNameIgnoreCaseComparer.Default.Equals(taskName, expectedTaskName); - private void CheckCompilerTask(BuildCheckDataContext context) { var taskParameters = context.Data.Parameters;