Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<MicrosoftBuildPackageVersion>17.14.8</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net8.0' ">17.11.4</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion>17.14.28</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net8.0'">17.11.48</MicrosoftBuildPackageVersion>
<MicrosoftBuildPackageVersion Condition="'$(TargetFramework)' == 'net10.0'">17.15.0-preview-25277-114</MicrosoftBuildPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AssemblyShader" Version="1.1.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,31 @@ public void ConsoleLog()
{
BuildEngine buildEngine = GetBuildEngineWithEvents(i =>
{
i.LogErrorEvent(new BuildErrorEventArgs(null, "A6DAB901460D483FBDF3A0980B14C46F", "48F7F352E2914991827100BCEB69331F", 3, 4, 0, 0, "D988473FF8634A16A0CD8FE94FF20D53", null, null));
i.LogWarningEvent(new BuildWarningEventArgs(null, "AE1B25881A694A70B2EA299C04625596", "07006F38A63E420AAB4124EBE58081BC", 1, 2, 0, 0, "3A3DD4A40DA44BA5BBB123E105EE1F71", null, null));
i.LogMessageEvent(new BuildMessageEventArgs("61BD637C7D704D4B98C25805E3111152", null, null, MessageImportance.High));
i.LogMessageEvent(new BuildMessageEventArgs("B02496FA4D3348A6997DC918EBF7455B", null, null, MessageImportance.Normal));
i.LogMessageEvent(new BuildMessageEventArgs("2C254C4346A347AE94AE5E7FB6C03B0C", null, null, MessageImportance.Low));
i.LogErrorEvent(
new BuildErrorEventArgs(null, "A6DAB901460D483FBDF3A0980B14C46F", "48F7F352E2914991827100BCEB69331F", 3, 4, 0, 0, "D988473FF8634A16A0CD8FE94FF20D53", null, null)
{
BuildEventContext = BuildEventContext.Invalid,
});
i.LogWarningEvent(
new BuildWarningEventArgs(null, "AE1B25881A694A70B2EA299C04625596", "07006F38A63E420AAB4124EBE58081BC", 1, 2, 0, 0, "3A3DD4A40DA44BA5BBB123E105EE1F71", null, null)
{
BuildEventContext = BuildEventContext.Invalid,
});
i.LogMessageEvent(
new BuildMessageEventArgs("61BD637C7D704D4B98C25805E3111152", null, null, MessageImportance.High)
{
BuildEventContext = BuildEventContext.Invalid,
});
i.LogMessageEvent(
new BuildMessageEventArgs("B02496FA4D3348A6997DC918EBF7455B", null, null, MessageImportance.Normal)
{
BuildEventContext = BuildEventContext.Invalid,
});
i.LogMessageEvent(
new BuildMessageEventArgs("2C254C4346A347AE94AE5E7FB6C03B0C", null, null, MessageImportance.Low)
{
BuildEventContext = BuildEventContext.Invalid,
});
});

buildEngine.GetConsoleLog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,44 @@ public void OnBuildFinished(bool succeeded, string? message = null, string? help

public void OnErrorRaised(string message, string? code = null, string? file = null, int lineNumber = -1, int columnNumber = -1, int endLineNumber = -1, int endColumnNumber = -1, string? helpKeyword = null, string? senderName = null)
{
BuildErrorEventArgs args = new BuildErrorEventArgs(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName);
BuildErrorEventArgs args = new BuildErrorEventArgs(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName)
{
BuildEventContext = BuildEventContext.Invalid,
};

ErrorRaised?.Invoke(this, args);
OnAnyEventRaised(args);
}

public void OnMessageRaised(string message, MessageImportance importance = MessageImportance.Normal)
{
BuildMessageEventArgs args = new BuildMessageEventArgs(message, null, null, importance);
BuildMessageEventArgs args = new BuildMessageEventArgs(message, null, null, importance)
{
BuildEventContext = BuildEventContext.Invalid,
};

MessageRaised?.Invoke(this, args);
OnAnyEventRaised(args);
}

public void OnProjectFinished(string projectFile, bool succeeded, string? message = null, string? helpKeyword = null)
{
ProjectFinishedEventArgs args = new ProjectFinishedEventArgs(message, helpKeyword, projectFile, succeeded);
ProjectFinishedEventArgs args = new ProjectFinishedEventArgs(message, helpKeyword, projectFile, succeeded)
{
BuildEventContext = BuildEventContext.Invalid,
};

ProjectFinished?.Invoke(this, args);
OnAnyEventRaised(args);
}

public void OnWarningRaised(string message, string? code = null, string? file = null, int lineNumber = -1, int columnNumber = -1, int endLineNumber = -1, int endColumnNumber = -1, string? helpKeyword = null, string? senderName = null)
{
BuildWarningEventArgs args = new BuildWarningEventArgs(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName);
BuildWarningEventArgs args = new BuildWarningEventArgs(null, code, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, helpKeyword, senderName)
{
BuildEventContext = BuildEventContext.Invalid,
};

WarningRaised?.Invoke(this, args);
OnAnyEventRaised(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Licensed under the MIT license.

using Microsoft.Build.Evaluation;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using System;
Expand Down Expand Up @@ -108,8 +109,16 @@ public virtual void Dispose()
/// Gets the current build output in the format of a console log.
/// </summary>
/// <param name="verbosity">The logger verbosity to use.</param>
/// <param name="showSummary">Optional parameter indicating whether or not to show an error and warning summary at the end.</param>
/// <param name="performanceSummary">Optional parameter indicating whether or not to show time spent in tasks, targets and projects.</param>
/// <param name="errorsOnly">Optional parameter indicating whether or not to show only errors.</param>
/// <param name="warningsOnly">Optional parameter indicating whether or not to show only warnings.</param>
/// <param name="showItemAndPropertyList">Optional parameter indicating whether or not to show a list of items and properties at the start of each project build.</param>
/// <param name="showCommandLine">Optional parameter indicating whether or not to show <see cref="TaskCommandLineEventArgs" /> messages.</param>
/// <param name="showTimestamp">Optional parameter indicating whether or not to show the timestamp as a prefix to any message.</param>
/// <param name="showEventId">Optional parameter indicating whether or not to show eventId for started events, finished events, and messages.</param>
/// <returns>The build output in the format of a console log.</returns>
public string GetConsoleLog(LoggerVerbosity verbosity = LoggerVerbosity.Normal)
public string GetConsoleLog(LoggerVerbosity verbosity = LoggerVerbosity.Normal, bool showSummary = true, bool performanceSummary = false, bool errorsOnly = false, bool warningsOnly = false, bool showItemAndPropertyList = true, bool showCommandLine = false, bool showTimestamp = false, bool showEventId = false)
{
if (_lastConsoleOutput != null && verbosity == _lastVerbosity)
{
Expand All @@ -118,65 +127,7 @@ public string GetConsoleLog(LoggerVerbosity verbosity = LoggerVerbosity.Normal)

_lastVerbosity = verbosity;

StringBuilder sb = new StringBuilder(AllEvents.Count * 300);

ConsoleLogger logger = new ConsoleLogger(verbosity, message => sb.Append(message), _ => { }, () => { });

foreach (BuildEventArgs buildEventArgs in AllEvents)
{
switch (buildEventArgs)
{
case BuildMessageEventArgs buildMessageEventArgs:
logger.MessageHandler(logger, buildMessageEventArgs);
break;

case BuildErrorEventArgs buildErrorEventArgs:
logger.ErrorHandler(logger, buildErrorEventArgs);
break;

case BuildWarningEventArgs buildWarningEventArgs:
logger.WarningHandler(logger, buildWarningEventArgs);
break;

case BuildStartedEventArgs buildStartedEventArgs:
logger.BuildStartedHandler(logger, buildStartedEventArgs);
break;

case BuildFinishedEventArgs buildFinishedEventArgs:
logger.BuildFinishedHandler(logger, buildFinishedEventArgs);
break;

case ProjectStartedEventArgs projectStartedEventArgs:
logger.ProjectStartedHandler(logger, projectStartedEventArgs);
break;

case ProjectFinishedEventArgs projectFinishedEventArgs:
logger.ProjectFinishedHandler(logger, projectFinishedEventArgs);
break;

case TargetStartedEventArgs targetStartedEventArgs:
logger.TargetStartedHandler(logger, targetStartedEventArgs);
break;

case TargetFinishedEventArgs targetFinishedEventArgs:
logger.TargetFinishedHandler(logger, targetFinishedEventArgs);
break;

case TaskStartedEventArgs taskStartedEventArgs:
logger.TaskStartedHandler(logger, taskStartedEventArgs);
break;

case TaskFinishedEventArgs taskFinishedEventArgs:
logger.TaskFinishedHandler(logger, taskFinishedEventArgs);
break;

case CustomBuildEventArgs customBuildEventArgs:
logger.CustomEventHandler(logger, customBuildEventArgs);
break;
}
}

_lastConsoleOutput = sb.ToString();
_lastConsoleOutput = ConsoleLoggerStringBuilder.GetConsoleLogAsString(AllEvents, verbosity, showSummary, performanceSummary, errorsOnly, warningsOnly, showItemAndPropertyList, showCommandLine, showTimestamp, showEventId);

ConsoleOutputCreated?.Invoke(this, verbosity);

Expand Down Expand Up @@ -209,4 +160,4 @@ protected void Add(BuildEventArgs buildEventArgs)
}
}
}
}
}
Loading