Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/Build.UnitTests/BackEnd/LoggingServicesLogMethod_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using Microsoft.Build.BackEnd;
using Microsoft.Build.BackEnd.Logging;
Expand Down Expand Up @@ -1089,7 +1090,7 @@ public void TaskStartedNullBuildEventContext()
Assert.Throws<InternalErrorException>(() =>
{
ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
service.LogTaskStarted(null, "MyTask", "ProjectFile", "ProjectFileOfTask");
service.LogTaskStarted(null, "MyTask", "ProjectFile", "ProjectFileOfTask", null);
});
}

Expand Down Expand Up @@ -1445,12 +1446,12 @@ private void TestTaskStartedEvent(string taskName, string projectFile, string pr
string message = ResourceUtilities.FormatResourceStringStripCodeAndKeyword("TaskStarted", taskName);

ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask);
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask, Assembly.GetExecutingAssembly().GetName());
VerifyTaskStartedEvent(taskName, projectFile, projectFileOfTask, message, service);

service.ResetProcessedBuildEvent();
service.OnlyLogCriticalEvents = true;
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask);
service.LogTaskStarted(s_buildEventContext, taskName, projectFile, projectFileOfTask, Assembly.GetExecutingAssembly().GetName());
Assert.Null(service.ProcessedBuildEvent);
}

Expand Down
7 changes: 5 additions & 2 deletions src/Build.UnitTests/BackEnd/MockLoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
Expand Down Expand Up @@ -573,7 +574,8 @@ public void LogTargetFinished(BuildEventContext targetBuildEventContext, string
/// <param name="taskName">The name of the task</param>
/// <param name="projectFile">The project file</param>
/// <param name="projectFileOfTaskNode">The project file containing the task node.</param>
public void LogTaskStarted(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode)
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented.</param>
public void LogTaskStarted(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, AssemblyName taskAssemblyName)
{
}

Expand All @@ -584,8 +586,9 @@ public void LogTaskStarted(BuildEventContext targetBuildEventContext, string tas
/// <param name="taskName">The name of the task</param>
/// <param name="projectFile">The project file</param>
/// <param name="projectFileOfTaskNode">The project file containing the task node.</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented.</param>
/// <returns>The task logging context</returns>
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column)
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column, AssemblyName taskAssemblyName)
{
return new BuildEventContext(0, 0, 0, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ private void InitializeHost(bool throwOnExecute)
CancellationToken.None);

ProjectTaskInstance taskInstance = project.Targets["foo"].Tasks.First();
TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance);
TaskLoggingContext talc = tlc.LogTaskBatchStarted(".", taskInstance, typeof(TaskBuilderTestTask.TaskBuilderTestTaskFactory).GetTypeInfo().Assembly.GetName());

ItemDictionary<ProjectItemInstance> itemsByName = new ItemDictionary<ProjectItemInstance>();

Expand Down
7 changes: 5 additions & 2 deletions src/Build/BackEnd/Components/Logging/ILoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -570,7 +571,8 @@ BuildEventContext LogProjectStarted(
/// <param name="taskName">The name of the task</param>
/// <param name="projectFile">The project file which is being built</param>
/// <param name="projectFileOfTaskNode">The file in which the task is defined - typically a .targets file</param>
void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode);
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented</param>
void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, AssemblyName taskAssemblyName);

/// <summary>
/// Log that a task is about to start
Expand All @@ -581,8 +583,9 @@ BuildEventContext LogProjectStarted(
/// <param name="projectFileOfTaskNode">The file in which the task is defined - typically a .targets file</param>
/// <param name="line">The line number in the file where the task invocation is located.</param>
/// <param name="column">The column number in the file where the task invocation is located.</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented.</param>
/// <returns>The task build event context</returns>
BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column);
BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column, AssemblyName taskAssemblyName);

/// <summary>
/// Log that a task has just completed
Expand Down
13 changes: 9 additions & 4 deletions src/Build/BackEnd/Components/Logging/LoggingServiceLogMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Profiler;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -688,8 +689,9 @@ public void LogTargetFinished(BuildEventContext targetBuildEventContext, string
/// <param name="taskName">Task Name</param>
/// <param name="projectFile">Project file being built</param>
/// <param name="projectFileOfTaskNode">Project file which contains the task</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented</param>
/// <exception cref="InternalErrorException">BuildEventContext is null</exception>
public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode)
public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, AssemblyName taskAssemblyName)
{
ErrorUtilities.VerifyThrow(taskBuildEventContext != null, "targetBuildEventContext is null");
if (!OnlyLogCriticalEvents)
Expand All @@ -699,7 +701,8 @@ public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskN
helpKeyword: null,
projectFile,
projectFileOfTaskNode,
taskName);
taskName,
taskAssemblyName);
buildEvent.BuildEventContext = taskBuildEventContext;
ProcessLoggingEvent(buildEvent);
}
Expand All @@ -714,9 +717,10 @@ public void LogTaskStarted(BuildEventContext taskBuildEventContext, string taskN
/// <param name="projectFileOfTaskNode">Project file which contains the task</param>
/// <param name="line">The line number in the file where the task invocation is located.</param>
/// <param name="column">The column number in the file where the task invocation is located.</param>
/// <param name="taskAssemblyName">An assembly's unique identity where the task is implemented</param>
/// <returns>The build event context for the task.</returns>
/// <exception cref="InternalErrorException">BuildEventContext is null</exception>
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column)
public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, int line, int column, AssemblyName taskAssemblyName)
{
ErrorUtilities.VerifyThrow(targetBuildEventContext != null, "targetBuildEventContext is null");
BuildEventContext taskBuildEventContext = new BuildEventContext(
Expand All @@ -734,7 +738,8 @@ public BuildEventContext LogTaskStarted2(BuildEventContext targetBuildEventConte
helpKeyword: null,
projectFile,
projectFileOfTaskNode,
taskName);
taskName,
taskAssemblyName);
buildEvent.BuildEventContext = taskBuildEventContext;
buildEvent.LineNumber = line;
buildEvent.ColumnNumber = column;
Expand Down
5 changes: 3 additions & 2 deletions src/Build/BackEnd/Components/Logging/TargetLoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -108,11 +109,11 @@ internal void LogTargetBatchFinished(string projectFullPath, bool success, IEnum
/// <summary>
/// Log that a task is about to start
/// </summary>
internal TaskLoggingContext LogTaskBatchStarted(string projectFullPath, ProjectTargetInstanceChild task)
internal TaskLoggingContext LogTaskBatchStarted(string projectFullPath, ProjectTargetInstanceChild task, AssemblyName taskAssemblyName)
{
ErrorUtilities.VerifyThrow(IsValid, "Should be valid");

return new TaskLoggingContext(this, projectFullPath, task);
return new TaskLoggingContext(this, projectFullPath, task, taskAssemblyName);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions src/Build/BackEnd/Components/Logging/TaskLoggingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
Expand Down Expand Up @@ -34,7 +35,7 @@ internal class TaskLoggingContext : BuildLoggingContext
/// <summary>
/// Constructs a task logging context from a parent target context and a task node.
/// </summary>
internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string projectFullPath, ProjectTargetInstanceChild task)
internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string projectFullPath, ProjectTargetInstanceChild task, AssemblyName taskAssemblyName)
: base(targetLoggingContext)
{
_targetLoggingContext = targetLoggingContext;
Expand Down Expand Up @@ -72,7 +73,8 @@ internal TaskLoggingContext(TargetLoggingContext targetLoggingContext, string pr
projectFullPath,
task.Location.File,
task.Location.Line,
task.Location.Column);
task.Location.Column,
taskAssemblyName);
this.IsValid = true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,11 @@ private async Task<WorkUnitResult> ExecuteBucket(TaskHost taskHost, ItemBucket b
// We need to find the task before logging the task started event so that the using task statement comes before the task started event
IDictionary<string, string> taskIdentityParameters = GatherTaskIdentityParameters(bucket.Expander);
TaskRequirements? requirements = _taskExecutionHost.FindTask(taskIdentityParameters);
AssemblyName taskAssemblyName = _taskExecutionHost.FindTaskAssemblyName(taskIdentityParameters);

if (requirements != null)
{
TaskLoggingContext taskLoggingContext = _targetLoggingContext.LogTaskBatchStarted(_projectFullPath, _targetChildInstance);
TaskLoggingContext taskLoggingContext = _targetLoggingContext.LogTaskBatchStarted(_projectFullPath, _targetChildInstance, taskAssemblyName);
MSBuildEventSource.Log.ExecuteTaskStart(_taskNode?.Name, taskLoggingContext.BuildEventContext.TaskId);
_buildRequestEntry.Request.CurrentTaskContext = taskLoggingContext.BuildEventContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
Expand All @@ -15,7 +16,7 @@
namespace Microsoft.Build.BackEnd
{
/// <summary>
/// Flags requrned by ITaskExecutionHost.FindTask().
/// Flags returned by ITaskExecutionHost.FindTask().
/// </summary>
[Flags]
internal enum TaskRequirements
Expand Down Expand Up @@ -74,6 +75,12 @@ void InitializeForTask(IBuildEngine2 buildEngine, TargetLoggingContext loggingCo
/// <returns>The task requirements if the task is found, null otherwise.</returns>
TaskRequirements? FindTask(IDictionary<string, string> taskIdentityParameters);

/// <summary>
/// Ask the task host to find task assembly name
/// </summary>
/// <returns>The task assembly name if the task is found, null otherwise.</returns>
AssemblyName FindTaskAssemblyName(IDictionary<string, string> taskIdentityParameters);

/// <summary>
/// Initializes for running a particular batch
/// </summary>
Expand Down
20 changes: 14 additions & 6 deletions src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,12 @@ void ITaskExecutionHost.InitializeForTask(IBuildEngine2 buildEngine, TargetLoggi
/// <summary>
/// Ask the task host to find its task in the registry and get it ready for initializing the batch
/// </summary>
/// <returns>True if the task is found in the task registry false if otherwise.</returns>
/// <returns>The task requirements if the task is found, null otherwise.</returns>
TaskRequirements? ITaskExecutionHost.FindTask(IDictionary<string, string> taskIdentityParameters)
{
if (_taskFactoryWrapper == null)
{
_taskFactoryWrapper = FindTaskInRegistry(taskIdentityParameters);
}
_taskFactoryWrapper ??= FindTaskInRegistry(taskIdentityParameters);

if (_taskFactoryWrapper == null)
if (_taskFactoryWrapper is null)
{
return null;
}
Expand All @@ -275,6 +272,17 @@ void ITaskExecutionHost.InitializeForTask(IBuildEngine2 buildEngine, TargetLoggi
return requirements;
}

/// <summary>
/// Ask the task host to find task assembly name
/// </summary>
/// <returns>The task assembly name if the task is found, null otherwise.</returns>
AssemblyName ITaskExecutionHost.FindTaskAssemblyName(IDictionary<string, string> taskIdentityParameters)
{
_taskFactoryWrapper ??= FindTaskInRegistry(taskIdentityParameters);

return _taskFactoryWrapper?.TaskFactoryLoadedType.LoadedAssemblyName;
}

/// <summary>
/// Initialize to run a specific batch of the current task.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion src/Build/Logging/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,14 +806,16 @@ private BuildEventArgs ReadTaskStartedEventArgs()
var taskName = ReadOptionalString();
var projectFile = ReadOptionalString();
var taskFile = ReadOptionalString();
var taskAssemblyNameString = ReadOptionalString();

var e = new TaskStartedEventArgs(
fields.Message,
fields.HelpKeyword,
projectFile,
taskFile,
taskName,
fields.Timestamp);
fields.Timestamp,
taskAssemblyNameString is null ? null : new AssemblyName(taskAssemblyNameString));
e.LineNumber = fields.LineNumber;
e.ColumnNumber = fields.ColumnNumber;
SetCommonFields(e, fields);
Expand Down
1 change: 1 addition & 0 deletions src/Build/Logging/BinaryLogger/BuildEventArgsWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ private BinaryLogRecordKind Write(TaskStartedEventArgs e)
WriteDeduplicatedString(e.TaskName);
WriteDeduplicatedString(e.ProjectFile);
WriteDeduplicatedString(e.TaskFile);
WriteDeduplicatedString(e.TaskAssemblyName?.FullName);

return BinaryLogRecordKind.TaskStarted;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Deprecated/Engine/Engine/EngineLoggingServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using Microsoft.Build.Framework;
using Microsoft.Build.BuildEngine.Shared;
using System.Reflection;

namespace Microsoft.Build.BuildEngine
{
Expand Down Expand Up @@ -863,7 +864,7 @@ internal virtual void LogTargetFinished(BuildEventContext buildEventContext, str
/// <param name="taskName"></param>
/// <param name="projectFile"></param>
/// <param name="projectFileOfTaskNode">project file actually containing the task</param>
internal virtual void LogTaskStarted(BuildEventContext buildEventContext, string taskName, string projectFile, string projectFileOfTaskNode)
internal virtual void LogTaskStarted(BuildEventContext buildEventContext, string taskName, string projectFile, string projectFileOfTaskNode, AssemblyName taskAssemblyName)
{
if (!OnlyLogCriticalEvents)
{
Expand All @@ -873,7 +874,8 @@ internal virtual void LogTaskStarted(BuildEventContext buildEventContext, string
null, // no help keyword
projectFile,
projectFileOfTaskNode,
taskName
taskName,
taskAssemblyName
);
e.BuildEventContext = buildEventContext;
PostLoggingEvent(e);
Expand Down
4 changes: 3 additions & 1 deletion src/Deprecated/Engine/Engine/TaskEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ private bool ExecuteBucket(EngineProxy engineProxy, ItemBucket bucket, int bucke
engineProxy.BuildEventContext = buildEventContext;
}

loggingServices.LogTaskStarted(buildEventContext, TaskName, parentProjectFullFileName, projectFileOfTaskNode);
AssemblyName taskAssemblyName = TaskClass is null ? null : new AssemblyName(TaskClass.Assembly.AssemblyName);

loggingServices.LogTaskStarted(buildEventContext, TaskName, parentProjectFullFileName, projectFileOfTaskNode, taskAssemblyName);

AppDomain taskAppDomain = PrepareAppDomain();

Expand Down
Loading