From aeb01678b40845e45408fc5313f5ddee01eba1c2 Mon Sep 17 00:00:00 2001 From: Mariana Garces Dematte Date: Tue, 3 Sep 2024 15:58:21 +0200 Subject: [PATCH 1/5] Added tests for Check failure --- src/BuildCheck.UnitTests/EndToEndTests.cs | 31 ++++++++++++++ ...icrosoft.Build.BuildCheck.UnitTests.csproj | 5 +++ .../.editorconfigtest | 3 ++ ...CandidateWithMultipleChecksInjected.csproj | 1 + .../ErrorCustomCheck/ErrorCustomCheck.csproj | 17 ++++++++ .../ErrorCustomCheck/ErrorCustomCheck.props | 6 +++ .../ErrorOnInitializeCheck.cs | 40 +++++++++++++++++++ .../ErrorOnRegisteredAction.cs | 36 +++++++++++++++++ .../ErrorWhenRegisteringActions.cs | 40 +++++++++++++++++++ .../TestAssets/ErrorCustomCheck/README.md | 21 ++++++++++ 10 files changed, 200 insertions(+) create mode 100644 src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.csproj create mode 100644 src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.props create mode 100644 src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs create mode 100644 src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs create mode 100644 src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs create mode 100644 src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/README.md diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs index 358f8725b90..083c8855d63 100644 --- a/src/BuildCheck.UnitTests/EndToEndTests.cs +++ b/src/BuildCheck.UnitTests/EndToEndTests.cs @@ -343,6 +343,37 @@ public void CustomCheckTest_WithEditorConfig(string checkCandidate, string ruleI } } + [Theory] + [InlineData("X01236", "Something went wrong initializing")] + [InlineData("X01237", "message")] + [InlineData("X01238", "message")] + public void CustomChecksFailGracefully(string ruleId, string expectedMessage) + { + using (var env = TestEnvironment.Create()) + { + string checkCandidate = "CheckCandidateWithMultipleChecksInjected"; + string checkCandidatePath = Path.Combine(TestAssetsRootPath, checkCandidate); + + // Can't use Transitive environment due to the need to dogfood local nuget packages. + AddCustomDataSourceToNugetConfig(checkCandidatePath); + string editorConfigName = Path.Combine(checkCandidatePath, EditorConfigFileName); + File.WriteAllText(editorConfigName, ReadEditorConfig( + new List<(string, string)>() { (ruleId, "warning") }, + ruleToCustomConfig: null, + checkCandidatePath)); + + string projectCheckBuildLog = RunnerUtilities.ExecBootstrapedMSBuild( + $"{Path.Combine(checkCandidatePath, $"{checkCandidate}.csproj")} /m:1 -nr:False -restore -check -verbosity:n", out bool success); + + success.ShouldBeTrue(); + projectCheckBuildLog.ShouldContain(expectedMessage); + projectCheckBuildLog.ShouldNotContain("This check should have been disabled"); + + // Cleanup + File.Delete(editorConfigName); + } + } + [Theory] [InlineData(true)] [InlineData(false)] diff --git a/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj b/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj index 3961ef049c3..cd82b6d45cd 100644 --- a/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj +++ b/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj @@ -20,6 +20,7 @@ + @@ -45,4 +46,8 @@ + + + + diff --git a/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest b/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest index be166e833cd..3d3407474ab 100644 --- a/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest +++ b/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest @@ -2,3 +2,6 @@ root = true [*.csproj] build_check.X01234.Severity=X01234Severity + +build_check.X01235.Severity=warning +build_check.X01236.Severity=warning diff --git a/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/CheckCandidateWithMultipleChecksInjected.csproj b/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/CheckCandidateWithMultipleChecksInjected.csproj index 07695e19e8e..5bac9f39137 100644 --- a/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/CheckCandidateWithMultipleChecksInjected.csproj +++ b/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/CheckCandidateWithMultipleChecksInjected.csproj @@ -9,6 +9,7 @@ + diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.csproj b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.csproj new file mode 100644 index 00000000000..8bce5a83d8c --- /dev/null +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.csproj @@ -0,0 +1,17 @@ + + + + + + netstandard2.0 + true + + + + + + + + + + diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.props b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.props new file mode 100644 index 00000000000..843a7176c4c --- /dev/null +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorCustomCheck.props @@ -0,0 +1,6 @@ + + + + $([MSBuild]::RegisterBuildCheck($(MSBuildThisFileDirectory)ErrorCustomCheck.dll)) + + diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs new file mode 100644 index 00000000000..1298ce99cf6 --- /dev/null +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using Microsoft.Build.Construction; +using Microsoft.Build.Experimental.BuildCheck; + +namespace ErrorCustomCheck +{ + public sealed class ErrorOnInitializeCheck : Check + { + public static CheckRule SupportedRule = new CheckRule( + "X01236", + "Title", + "Description", + "Message format: {0}", + new CheckConfiguration()); + + public override string FriendlyName => "ErrorOnInitializeCheck"; + + public override IReadOnlyList SupportedRules { get; } = new List() { SupportedRule }; + + public override void Initialize(ConfigurationContext configurationContext) + { + // configurationContext to be used only if check needs external configuration data. + throw new Exception("Something went wrong initializing"); + } + + public override void RegisterActions(IBuildCheckRegistrationContext registrationContext) + { + registrationContext.RegisterEvaluatedPropertiesAction(EvaluatedPropertiesAction); + } + + private void EvaluatedPropertiesAction(BuildCheckDataContext context) + { + context.ReportResult(BuildCheckResult.Create( + SupportedRule, + ElementLocation.EmptyLocation, + "This check should have been disabled")); + } + } +} diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs new file mode 100644 index 00000000000..d9655c04f19 --- /dev/null +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using Microsoft.Build.Construction; +using Microsoft.Build.Experimental.BuildCheck; + +namespace ErrorCustomCheck +{ + public sealed class ErrorOnRegisteredAction : Check + { + public static CheckRule SupportedRule = new CheckRule( + "X01237", + "Title", + "Description", + "Message format: {0}", + new CheckConfiguration()); + + public override string FriendlyName => "ErrorOnEvaluatedPropertiesCheck"; + + public override IReadOnlyList SupportedRules { get; } = new List() { SupportedRule }; + + public override void Initialize(ConfigurationContext configurationContext) + { + // configurationContext to be used only if check needs external configuration data. + } + + public override void RegisterActions(IBuildCheckRegistrationContext registrationContext) + { + registrationContext.RegisterEvaluatedPropertiesAction(EvaluatedPropertiesAction); + } + + private void EvaluatedPropertiesAction(BuildCheckDataContext context) + { + throw new Exception("something went wrong"); + } + } +} diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs new file mode 100644 index 00000000000..675ed03a54f --- /dev/null +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using Microsoft.Build.Construction; +using Microsoft.Build.Experimental.BuildCheck; + +namespace ErrorCustomCheck +{ + public sealed class ErrorWhenRegisteringActions : Check + { + public static CheckRule SupportedRule = new CheckRule( + "X01238", + "Title", + "Description", + "Message format: {0}", + new CheckConfiguration()); + + public override string FriendlyName => "ErrorOnEvaluatedPropertiesCheck"; + + public override IReadOnlyList SupportedRules { get; } = new List() { SupportedRule }; + + public override void Initialize(ConfigurationContext configurationContext) + { + // configurationContext to be used only if check needs external configuration data. + } + + public override void RegisterActions(IBuildCheckRegistrationContext registrationContext) + { + registrationContext.RegisterEvaluatedPropertiesAction(EvaluatedPropertiesAction); + throw new Exception("something went wrong"); + } + + private void EvaluatedPropertiesAction(BuildCheckDataContext context) + { + context.ReportResult(BuildCheckResult.Create( + SupportedRule, + ElementLocation.EmptyLocation, + "This check should have been disabled")); + } + } +} diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/README.md b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/README.md new file mode 100644 index 00000000000..ef41e00277e --- /dev/null +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/README.md @@ -0,0 +1,21 @@ +# MSBuild Custom Check Template + +## Overview +MSBuild Custom Check Template is a .NET template designed to streamline the creation of MSBuild check libraries. This template facilitates the development of custom checks targeting .NET Standard, enabling developers to inspect and enforce conventions, standards, or patterns within their MSBuild builds. + +## Features +- Simplified template for creating MSBuild check libraries. +- Targeting .NET Standard for cross-platform compatibility. +- Provides a starting point for implementing custom check rules. + +## Getting Started +To use the MSBuild Custom Check Template, follow these steps: +1. Install the template using the following command: + ```bash + dotnet new install msbuildcheck +2. Instantiate a custom template: + ```bash + dotnet new msbuildcheck -n + +### Prerequisites +- .NET SDK installed on your machine. From 3f95384380b03b98b26618bd9900fff0aa2cdc32 Mon Sep 17 00:00:00 2001 From: Mariana Garces Dematte Date: Tue, 3 Sep 2024 16:30:06 +0200 Subject: [PATCH 2/5] Send Check initialization exceptions as warnings --- .../Components/Logging/EventSourceSink.cs | 1 + .../BackEnd/Shared/EventsCreatorHelper.cs | 31 ++++++++++++++++++ .../BuildCheckManagerProvider.cs | 32 +++++++++++++++---- .../CheckContext/CheckDispatchingContext.cs | 7 ++++ .../CheckContext/CheckLoggingContext.cs | 4 +++ .../CheckContext/ICheckContext.cs | 5 +++ src/BuildCheck.UnitTests/EndToEndTests.cs | 4 +-- .../.editorconfigtest | 5 +-- 8 files changed, 79 insertions(+), 10 deletions(-) diff --git a/src/Build/BackEnd/Components/Logging/EventSourceSink.cs b/src/Build/BackEnd/Components/Logging/EventSourceSink.cs index 8804918dbc0..21e84951836 100644 --- a/src/Build/BackEnd/Components/Logging/EventSourceSink.cs +++ b/src/Build/BackEnd/Components/Logging/EventSourceSink.cs @@ -8,6 +8,7 @@ using Microsoft.Build.Shared; using InternalLoggerException = Microsoft.Build.Exceptions.InternalLoggerException; +using System.Diagnostics; #nullable disable diff --git a/src/Build/BackEnd/Shared/EventsCreatorHelper.cs b/src/Build/BackEnd/Shared/EventsCreatorHelper.cs index ead0c205d27..c097861214a 100644 --- a/src/Build/BackEnd/Shared/EventsCreatorHelper.cs +++ b/src/Build/BackEnd/Shared/EventsCreatorHelper.cs @@ -60,4 +60,35 @@ public static BuildErrorEventArgs CreateErrorEventFromText(BuildEventContext bui return buildEvent; } + + public static BuildWarningEventArgs CreateWarningEventFromText(BuildEventContext buildEventContext, string? subcategoryResourceName, string? errorCode, string? helpKeyword, BuildEventFileInfo file, string message) + { + ErrorUtilities.VerifyThrowInternalNull(buildEventContext, nameof(buildEventContext)); + ErrorUtilities.VerifyThrowInternalNull(file, nameof(file)); + ErrorUtilities.VerifyThrowInternalNull(message, nameof(message)); + + string? subcategory = null; + + if (subcategoryResourceName != null) + { + subcategory = AssemblyResources.GetString(subcategoryResourceName); + } + + BuildWarningEventArgs buildEvent = + new BuildWarningEventArgs( + subcategory, + errorCode, + file!.File, + file.Line, + file.Column, + file.EndLine, + file.EndColumn, + message, + helpKeyword, + "MSBuild"); + + buildEvent.BuildEventContext = buildEventContext; + + return buildEvent; + } } diff --git a/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs b/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs index 96a57e974ef..fb662e4d4c1 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs @@ -188,6 +188,7 @@ internal void RegisterCustomCheck( { if (_enabledDataSources[(int)buildCheckDataSource]) { + List checksToRemove = new(); foreach (var factory in factories) { var instance = factory(); @@ -201,10 +202,24 @@ internal void RegisterCustomCheck( if (checkFactoryContext != null) { _checkRegistry.Add(checkFactoryContext); - SetupSingleCheck(checkFactoryContext, projectPath); - checkContext.DispatchAsComment(MessageImportance.Normal, "CustomCheckSuccessfulAcquisition", instance.FriendlyName); + try + { + SetupSingleCheck(checkFactoryContext, projectPath); + checkContext.DispatchAsComment(MessageImportance.Normal, "CustomCheckSuccessfulAcquisition", instance.FriendlyName); + } + catch (BuildCheckConfigurationException e) + { + checkContext.DispatchAsWarningFromText( + null, + null, + null, + new BuildEventFileInfo(projectPath), + e.Message); + checksToRemove.Add(checkFactoryContext); + } } } + RemoveChecks(checksToRemove, checkContext); } } } @@ -295,7 +310,7 @@ private void SetupChecksForNewProject(string projectFullPath, ICheckContext chec } catch (BuildCheckConfigurationException e) { - checkContext.DispatchAsErrorFromText( + checkContext.DispatchAsWarningFromText( null, null, null, @@ -305,6 +320,14 @@ private void SetupChecksForNewProject(string projectFullPath, ICheckContext chec } } + RemoveChecks(checksToRemove, checkContext); + + stopwatch.Stop(); + _tracingReporter.AddNewProjectStats(stopwatch.Elapsed); + } + + private void RemoveChecks(List checksToRemove, ICheckContext checkContext) + { checksToRemove.ForEach(c => { _checkRegistry.Remove(c); @@ -316,9 +339,6 @@ private void SetupChecksForNewProject(string projectFullPath, ICheckContext chec _tracingReporter.AddCheckStats(checkToRemove!.Check.FriendlyName, checkToRemove.Elapsed); checkToRemove.Check.Dispose(); } - - stopwatch.Stop(); - _tracingReporter.AddNewProjectStats(stopwatch.Elapsed); } public void ProcessEvaluationFinishedEventArgs( diff --git a/src/Build/BuildCheck/Infrastructure/CheckContext/CheckDispatchingContext.cs b/src/Build/BuildCheck/Infrastructure/CheckContext/CheckDispatchingContext.cs index 71befe7991b..584bedca51e 100644 --- a/src/Build/BuildCheck/Infrastructure/CheckContext/CheckDispatchingContext.cs +++ b/src/Build/BuildCheck/Infrastructure/CheckContext/CheckDispatchingContext.cs @@ -62,4 +62,11 @@ public void DispatchAsErrorFromText(string? subcategoryResourceName, string? err _eventDispatcher.Dispatch(buildEvent); } + + public void DispatchAsWarningFromText(string? subcategoryResourceName, string? errorCode, string? helpKeyword, BuildEventFileInfo file, string message) + { + BuildWarningEventArgs buildEvent = EventsCreatorHelper.CreateWarningEventFromText(_eventContext, subcategoryResourceName, errorCode, helpKeyword, file, message); + + _eventDispatcher.Dispatch(buildEvent); + } } diff --git a/src/Build/BuildCheck/Infrastructure/CheckContext/CheckLoggingContext.cs b/src/Build/BuildCheck/Infrastructure/CheckContext/CheckLoggingContext.cs index c295b254f49..8c15478a702 100644 --- a/src/Build/BuildCheck/Infrastructure/CheckContext/CheckLoggingContext.cs +++ b/src/Build/BuildCheck/Infrastructure/CheckContext/CheckLoggingContext.cs @@ -39,4 +39,8 @@ public void DispatchAsCommentFromText(MessageImportance importance, string messa public void DispatchAsErrorFromText(string? subcategoryResourceName, string? errorCode, string? helpKeyword, BuildEventFileInfo file, string message) => loggingService .LogErrorFromText(eventContext, subcategoryResourceName, errorCode, helpKeyword, file, message); + + public void DispatchAsWarningFromText(string? subcategoryResourceName, string? errorCode, string? helpKeyword, BuildEventFileInfo file, string message) + => loggingService + .LogWarningFromText(eventContext, subcategoryResourceName, errorCode, helpKeyword, file, message); } diff --git a/src/Build/BuildCheck/Infrastructure/CheckContext/ICheckContext.cs b/src/Build/BuildCheck/Infrastructure/CheckContext/ICheckContext.cs index 7c4e82861ea..0f592d129d6 100644 --- a/src/Build/BuildCheck/Infrastructure/CheckContext/ICheckContext.cs +++ b/src/Build/BuildCheck/Infrastructure/CheckContext/ICheckContext.cs @@ -40,4 +40,9 @@ internal interface ICheckContext /// Dispatch the instance of as a comment with provided text for the message. /// void DispatchAsCommentFromText(MessageImportance importance, string message); + + /// + /// Dispatch the instance of as a warning message. + /// + void DispatchAsWarningFromText(string? subcategoryResourceName, string? errorCode, string? helpKeyword, BuildEventFileInfo file, string message); } diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs index 083c8855d63..9b076615ccb 100644 --- a/src/BuildCheck.UnitTests/EndToEndTests.cs +++ b/src/BuildCheck.UnitTests/EndToEndTests.cs @@ -345,8 +345,8 @@ public void CustomCheckTest_WithEditorConfig(string checkCandidate, string ruleI [Theory] [InlineData("X01236", "Something went wrong initializing")] - [InlineData("X01237", "message")] - [InlineData("X01238", "message")] + // [InlineData("X01237", "message")] + // [InlineData("X01238", "message")] public void CustomChecksFailGracefully(string ruleId, string expectedMessage) { using (var env = TestEnvironment.Create()) diff --git a/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest b/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest index 3d3407474ab..9fc4aa489e8 100644 --- a/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest +++ b/src/BuildCheck.UnitTests/TestAssets/CheckCandidateWithMultipleChecksInjected/.editorconfigtest @@ -3,5 +3,6 @@ root = true [*.csproj] build_check.X01234.Severity=X01234Severity -build_check.X01235.Severity=warning -build_check.X01236.Severity=warning +build_check.X01236.Severity=X01236Severity +build_check.X01237.Severity=X01237Severity +build_check.X01238.Severity=X01238Severity From 950ba172052accf04c0f120406092a33a6d510d1 Mon Sep 17 00:00:00 2001 From: Mariana Garces Dematte Date: Wed, 4 Sep 2024 14:14:21 +0200 Subject: [PATCH 3/5] Address some left overs from dev --- src/Build/BackEnd/Components/Logging/EventSourceSink.cs | 1 - src/BuildCheck.UnitTests/EndToEndTests.cs | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Build/BackEnd/Components/Logging/EventSourceSink.cs b/src/Build/BackEnd/Components/Logging/EventSourceSink.cs index 21e84951836..8804918dbc0 100644 --- a/src/Build/BackEnd/Components/Logging/EventSourceSink.cs +++ b/src/Build/BackEnd/Components/Logging/EventSourceSink.cs @@ -8,7 +8,6 @@ using Microsoft.Build.Shared; using InternalLoggerException = Microsoft.Build.Exceptions.InternalLoggerException; -using System.Diagnostics; #nullable disable diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs index 9b076615ccb..0bfb09e4dfa 100644 --- a/src/BuildCheck.UnitTests/EndToEndTests.cs +++ b/src/BuildCheck.UnitTests/EndToEndTests.cs @@ -345,6 +345,8 @@ public void CustomCheckTest_WithEditorConfig(string checkCandidate, string ruleI [Theory] [InlineData("X01236", "Something went wrong initializing")] + // These tests are for failure one different points, will be addressed in a different PR + // https://github.com/dotnet/msbuild/issues/10522 // [InlineData("X01237", "message")] // [InlineData("X01238", "message")] public void CustomChecksFailGracefully(string ruleId, string expectedMessage) From 5a8f59d30d4d57f190051eb5c3bf38775fdc844b Mon Sep 17 00:00:00 2001 From: Mariana Garces Dematte Date: Wed, 4 Sep 2024 14:16:52 +0200 Subject: [PATCH 4/5] Leftovers p2 --- .../Microsoft.Build.BuildCheck.UnitTests.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj b/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj index cd82b6d45cd..27bf2a1542b 100644 --- a/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj +++ b/src/BuildCheck.UnitTests/Microsoft.Build.BuildCheck.UnitTests.csproj @@ -46,8 +46,4 @@ - - - - From e9e5a574b10d13960fed7f647c1ecc1ce675dcd7 Mon Sep 17 00:00:00 2001 From: Mariana Garces Dematte Date: Thu, 5 Sep 2024 14:11:24 +0200 Subject: [PATCH 5/5] PR comments and file headers --- .../Infrastructure/BuildCheckManagerProvider.cs | 12 ++++++------ .../ErrorCustomCheck/ErrorOnInitializeCheck.cs | 5 ++++- .../ErrorCustomCheck/ErrorOnRegisteredAction.cs | 5 ++++- .../ErrorCustomCheck/ErrorWhenRegisteringActions.cs | 5 ++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs b/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs index fb662e4d4c1..d219233aedb 100644 --- a/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs +++ b/src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs @@ -188,7 +188,7 @@ internal void RegisterCustomCheck( { if (_enabledDataSources[(int)buildCheckDataSource]) { - List checksToRemove = new(); + List invalidChecksToRemove = new(); foreach (var factory in factories) { var instance = factory(); @@ -215,11 +215,11 @@ internal void RegisterCustomCheck( null, new BuildEventFileInfo(projectPath), e.Message); - checksToRemove.Add(checkFactoryContext); + invalidChecksToRemove.Add(checkFactoryContext); } } } - RemoveChecks(checksToRemove, checkContext); + RemoveChecks(invalidChecksToRemove, checkContext); } } } @@ -301,7 +301,7 @@ private void SetupChecksForNewProject(string projectFullPath, ICheckContext chec // If it's already constructed - just control the custom settings do not differ Stopwatch stopwatch = Stopwatch.StartNew(); - List checksToRemove = new(); + List invalidChecksToRemove = new(); foreach (CheckFactoryContext checkFactoryContext in _checkRegistry) { try @@ -316,11 +316,11 @@ private void SetupChecksForNewProject(string projectFullPath, ICheckContext chec null, new BuildEventFileInfo(projectFullPath), e.Message); - checksToRemove.Add(checkFactoryContext); + invalidChecksToRemove.Add(checkFactoryContext); } } - RemoveChecks(checksToRemove, checkContext); + RemoveChecks(invalidChecksToRemove, checkContext); stopwatch.Stop(); _tracingReporter.AddNewProjectStats(stopwatch.Elapsed); diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs index 1298ce99cf6..9500479932d 100644 --- a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnInitializeCheck.cs @@ -1,4 +1,7 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; using System.Collections.Generic; using Microsoft.Build.Construction; using Microsoft.Build.Experimental.BuildCheck; diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs index d9655c04f19..1593dc9b997 100644 --- a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorOnRegisteredAction.cs @@ -1,4 +1,7 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; using System.Collections.Generic; using Microsoft.Build.Construction; using Microsoft.Build.Experimental.BuildCheck; diff --git a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs index 675ed03a54f..9b3f5f0cf05 100644 --- a/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs +++ b/src/BuildCheck.UnitTests/TestAssets/ErrorCustomCheck/ErrorWhenRegisteringActions.cs @@ -1,4 +1,7 @@ -using System; +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; using System.Collections.Generic; using Microsoft.Build.Construction; using Microsoft.Build.Experimental.BuildCheck;