diff --git a/ref/net46/Microsoft.Build/Microsoft.Build.cs b/ref/net46/Microsoft.Build/Microsoft.Build.cs index a5b7e11a2ea..336c12ced25 100644 --- a/ref/net46/Microsoft.Build/Microsoft.Build.cs +++ b/ref/net46/Microsoft.Build/Microsoft.Build.cs @@ -941,6 +941,7 @@ public BuildParameters(Microsoft.Build.Evaluation.ProjectCollection projectColle public System.Globalization.CultureInfo UICulture { get { throw null; } set { } } public bool UseSynchronousLogging { get { throw null; } set { } } public System.Collections.Generic.ISet WarningsAsErrors { get { throw null; } set { } } + public System.Collections.Generic.ISet WarningsAsMessages { get { throw null; } set { } } public Microsoft.Build.Execution.BuildParameters Clone() { throw null; } public Microsoft.Build.Evaluation.Toolset GetToolset(string toolsVersion) { throw null; } } diff --git a/src/XMakeBuildEngine/BackEnd/BuildManager/BuildManager.cs b/src/XMakeBuildEngine/BackEnd/BuildManager/BuildManager.cs index 92872a5e736..0cb3cdd8a8d 100644 --- a/src/XMakeBuildEngine/BackEnd/BuildManager/BuildManager.cs +++ b/src/XMakeBuildEngine/BackEnd/BuildManager/BuildManager.cs @@ -424,7 +424,7 @@ public void BeginBuild(BuildParameters parameters) } // Set up the logging service. - ILoggingService loggingService = CreateLoggingService(_buildParameters.Loggers, _buildParameters.ForwardingLoggers, _buildParameters.WarningsAsErrors); + ILoggingService loggingService = CreateLoggingService(_buildParameters.Loggers, _buildParameters.ForwardingLoggers, _buildParameters.WarningsAsErrors, _buildParameters.WarningsAsMessages); _nodeManager.RegisterPacketHandler(NodePacketType.LogMessage, LogMessagePacket.FactoryForDeserialization, loggingService as INodePacketHandler); try @@ -1736,7 +1736,7 @@ private void OnProjectStarted(object sender, ProjectStartedEventArgs e) /// /// Creates a logging service around the specified set of loggers. /// - private ILoggingService CreateLoggingService(IEnumerable loggers, IEnumerable forwardingLoggers, ISet warningsAsErrors) + private ILoggingService CreateLoggingService(IEnumerable loggers, IEnumerable forwardingLoggers, ISet warningsAsErrors, ISet warningsAsMessages) { int cpuCount = _buildParameters.MaxNodeCount; @@ -1764,6 +1764,7 @@ private ILoggingService CreateLoggingService(IEnumerable loggers, IEnum loggingService.OnProjectStarted += _projectStartedEventHandler; loggingService.OnProjectFinished += _projectFinishedEventHandler; loggingService.WarningsAsErrors = warningsAsErrors; + loggingService.WarningsAsMessages = warningsAsMessages; try { diff --git a/src/XMakeBuildEngine/BackEnd/BuildManager/BuildParameters.cs b/src/XMakeBuildEngine/BackEnd/BuildManager/BuildParameters.cs index 34459823cfc..5ef4bda7a87 100644 --- a/src/XMakeBuildEngine/BackEnd/BuildManager/BuildParameters.cs +++ b/src/XMakeBuildEngine/BackEnd/BuildManager/BuildParameters.cs @@ -205,6 +205,11 @@ public class BuildParameters : INodePacketTranslatable /// private ISet _warningsAsErrors = null; + /// + /// A list of warnings to treat as low importance messages. + /// + private ISet _warningsAsMessages = null; + /// /// The location of the toolset definitions. /// @@ -326,6 +331,7 @@ private BuildParameters(BuildParameters other) _logTaskInputs = other._logTaskInputs; _logInitialPropertiesAndItems = other._logInitialPropertiesAndItems; _warningsAsErrors = other._warningsAsErrors == null ? null : new HashSet(other._warningsAsErrors, StringComparer.OrdinalIgnoreCase); + _warningsAsMessages = other._warningsAsMessages == null ? null : new HashSet(other._warningsAsMessages, StringComparer.OrdinalIgnoreCase); } #if FEATURE_THREAD_PRIORITY @@ -598,6 +604,15 @@ public ISet WarningsAsErrors set { _warningsAsErrors = value; } } + /// + /// A list of warnings to treat as low importance messages. + /// + public ISet WarningsAsMessages + { + get { return _warningsAsMessages; } + set { _warningsAsMessages = value; } + } + /// /// Locations to search for toolsets. /// diff --git a/src/XMakeBuildEngine/BackEnd/Components/Logging/BuildEventArgTransportSink.cs b/src/XMakeBuildEngine/BackEnd/Components/Logging/BuildEventArgTransportSink.cs index bce7890e6de..64e1d9e8f6c 100644 --- a/src/XMakeBuildEngine/BackEnd/Components/Logging/BuildEventArgTransportSink.cs +++ b/src/XMakeBuildEngine/BackEnd/Components/Logging/BuildEventArgTransportSink.cs @@ -90,6 +90,16 @@ public ISet WarningsAsErrors set; } + /// + /// This property is ignored by this event sink and relies on the receiver to treat warnings as low importance messages. + /// + public ISet WarningsAsMessages + { + get; + set; + } + + /// /// This property is ignored by this event sink and relies on the receiver to keep track of whether or not any errors have been logged. /// diff --git a/src/XMakeBuildEngine/BackEnd/Components/Logging/EventSourceSink.cs b/src/XMakeBuildEngine/BackEnd/Components/Logging/EventSourceSink.cs index c023231b9bf..c13dcb89f32 100644 --- a/src/XMakeBuildEngine/BackEnd/Components/Logging/EventSourceSink.cs +++ b/src/XMakeBuildEngine/BackEnd/Components/Logging/EventSourceSink.cs @@ -140,6 +140,15 @@ public ISet WarningsAsErrors set; } + /// + /// A list of warnings to treat as low importance messages. + /// + public ISet WarningsAsMessages + { + get; + set; + } + /// /// A list of build submission IDs that have logged errors. If an error is logged outside of a submission, the submission ID is . /// @@ -224,9 +233,33 @@ public void Consume(BuildEventArgs buildEvent) { BuildWarningEventArgs warningEvent = (BuildWarningEventArgs) buildEvent; - // Treat this warning as an error if an empty set of warnings was specified or this code was specified - if (WarningsAsErrors != null && (WarningsAsErrors.Count == 0 || WarningsAsErrors.Contains(warningEvent.Code))) + if (WarningsAsMessages != null && WarningsAsMessages.Contains(warningEvent.Code)) + { + // Treat this warning as a message with low importance if its in the list + BuildMessageEventArgs errorEvent = new BuildMessageEventArgs( + warningEvent.Subcategory, + warningEvent.Code, + warningEvent.File, + warningEvent.LineNumber, + warningEvent.ColumnNumber, + warningEvent.EndLineNumber, + warningEvent.EndColumnNumber, + warningEvent.Message, + warningEvent.HelpKeyword, + warningEvent.SenderName, + MessageImportance.Low, + warningEvent.Timestamp) + { + BuildEventContext = warningEvent.BuildEventContext, + ProjectFile = warningEvent.ProjectFile, + }; + + this.RaiseMessageEvent(null, errorEvent); + + } + else if (WarningsAsErrors != null && (WarningsAsErrors.Count == 0 || WarningsAsErrors.Contains(warningEvent.Code))) { + // Treat this warning as an error if an empty set of warnings was specified or this code was specified BuildErrorEventArgs errorEvent = new BuildErrorEventArgs( warningEvent.Subcategory, warningEvent.Code, diff --git a/src/XMakeBuildEngine/BackEnd/Components/Logging/ILoggingService.cs b/src/XMakeBuildEngine/BackEnd/Components/Logging/ILoggingService.cs index 9e4f0c1e068..7a6caf13b81 100644 --- a/src/XMakeBuildEngine/BackEnd/Components/Logging/ILoggingService.cs +++ b/src/XMakeBuildEngine/BackEnd/Components/Logging/ILoggingService.cs @@ -162,6 +162,15 @@ ISet WarningsAsErrors get; set; } + + /// + /// A list of warnings to treat as low importance messages. + /// + ISet WarningsAsMessages + { + get; + set; + } #endregion /// @@ -472,6 +481,15 @@ ISet WarningsAsErrors set; } + /// + /// A list of warnings to treat as low importance messages. + /// + ISet WarningsAsMessages + { + get; + set; + } + /// /// A list of build submissions that have logged errors. /// diff --git a/src/XMakeBuildEngine/BackEnd/Components/Logging/LoggingService.cs b/src/XMakeBuildEngine/BackEnd/Components/Logging/LoggingService.cs index 0d0c55e08fd..fc3ac97b501 100644 --- a/src/XMakeBuildEngine/BackEnd/Components/Logging/LoggingService.cs +++ b/src/XMakeBuildEngine/BackEnd/Components/Logging/LoggingService.cs @@ -224,6 +224,11 @@ internal partial class LoggingService : ILoggingService, INodePacketHandler, IBu /// private ISet _warningsAsErrors = null; + /// + /// A list of warnings to treat as low importance messages. + /// + private ISet _warningsAsMessages = null; + #endregion #endregion @@ -459,6 +464,15 @@ public ISet WarningsAsErrors set { _warningsAsErrors = value; } } + /// + /// A list of warnings to treat as low importance messages. + /// + public ISet WarningsAsMessages + { + get { return _warningsAsMessages; } + set { _warningsAsMessages = value; } + } + /// /// Determines if the specified submission has logged an errors. /// @@ -819,7 +833,8 @@ public bool RegisterDistributedLogger(ILogger centralLogger, LoggerDescription f // create an eventSourceSink which the central logger will register with to receive the events from the forwarding logger EventSourceSink eventSourceSink = new EventSourceSink { - WarningsAsErrors = WarningsAsErrors == null ? null : new HashSet(WarningsAsErrors, StringComparer.OrdinalIgnoreCase) + WarningsAsErrors = WarningsAsErrors == null ? null : new HashSet(WarningsAsErrors, StringComparer.OrdinalIgnoreCase), + WarningsAsMessages = WarningsAsMessages == null ? null : new HashSet(WarningsAsMessages, StringComparer.OrdinalIgnoreCase), }; // If the logger is already in the list it should not be registered again. @@ -1135,7 +1150,8 @@ private void CreateFilterEventSource() _filterEventSource = new EventSourceSink { Name = "Sink for Distributed/Filter loggers", - WarningsAsErrors = WarningsAsErrors == null ? null : new HashSet(WarningsAsErrors, StringComparer.OrdinalIgnoreCase) + WarningsAsErrors = WarningsAsErrors == null ? null : new HashSet(WarningsAsErrors, StringComparer.OrdinalIgnoreCase), + WarningsAsMessages = WarningsAsMessages == null ? null : new HashSet(WarningsAsMessages, StringComparer.OrdinalIgnoreCase), }; } } diff --git a/src/XMakeBuildEngine/UnitTests/BackEnd/MockLoggingService.cs b/src/XMakeBuildEngine/UnitTests/BackEnd/MockLoggingService.cs index c3559fac92b..6b8269d6eae 100644 --- a/src/XMakeBuildEngine/UnitTests/BackEnd/MockLoggingService.cs +++ b/src/XMakeBuildEngine/UnitTests/BackEnd/MockLoggingService.cs @@ -156,6 +156,14 @@ public ISet WarningsAsErrors set; } + /// + /// List of warnings to treat as low importance messages. + /// + public ISet WarningsAsMessages + { + get; + set; + } /// /// Is the logging service on a remote node, this is used to determine if properties need to be serialized diff --git a/src/XMakeCommandLine/CommandLineSwitches.cs b/src/XMakeCommandLine/CommandLineSwitches.cs index be2786a7d77..d37b937dbb1 100644 --- a/src/XMakeCommandLine/CommandLineSwitches.cs +++ b/src/XMakeCommandLine/CommandLineSwitches.cs @@ -103,6 +103,7 @@ internal enum ParameterizedSwitch ServerToClientPipeHandle, #endif WarningsAsErrors, + WarningsAsMessages, NumberOfParameterizedSwitches } @@ -281,6 +282,7 @@ bool emptyParametersAllowed new ParameterizedSwitchInfo( new string[] { "serverToClientPipeHandle", "s2c" }, ParameterizedSwitch.ServerToClientPipeHandle, null, false, null, true, false ), #endif new ParameterizedSwitchInfo( new string[] { "warnaserror", "err" }, ParameterizedSwitch.WarningsAsErrors, null, true, null, true, true ), + new ParameterizedSwitchInfo( new string[] { "warnasmessage", "nowarn" }, ParameterizedSwitch.WarningsAsMessages, null, true, "MissingWarnAsMessageParameterError", true, false ), }; /// diff --git a/src/XMakeCommandLine/Resources/Strings.resx b/src/XMakeCommandLine/Resources/Strings.resx index 18bbfd134f7..7af49bc1705 100644 --- a/src/XMakeCommandLine/Resources/Strings.resx +++ b/src/XMakeCommandLine/Resources/Strings.resx @@ -601,7 +601,22 @@ Copyright (C) Microsoft Corporation. All rights reserved. build will fail. - LOCALIZATION: "warnaserror" should not be localized. + LOCALIZATION: "/warnaserror" and "/err" should not be localized. + LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. + + + + /warnasmessage[:code[;code2]] + List of warning codes to treats as low importance + messages. Use a semicolon or a comma to separate + multiple warning codes. + (Short form: /nowarn[:c;[c2]]) + + Example: + /warnasmessage:MSB3026 + + + LOCALIZATION: "/warnasmessage" and "/nowarn" should not be localized. LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars. @@ -975,6 +990,14 @@ Copyright (C) Microsoft Corporation. All rights reserved. {0} ({1},{2}) A file location to be embedded in a string. + + MSBUILD : error MSB1050: Specify one or more warning codes to treat as low importance messages when using the /warnasmessage switch. + + {StrBegin="MSBUILD : error MSB1050: "} + UE: This happens if the user does something like "msbuild.exe /warnasmessage:" without any codes. + LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized. + +