Skip to content
Closed
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
11 changes: 3 additions & 8 deletions src/Build.UnitTests/BackEnd/AssemblyTaskFactory_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public class AssemblyTaskFactory_Tests
/// </summary>
private AssemblyLoadInfo _loadInfo;

/// <summary>
/// The loaded type from the initialized task factory.
/// </summary>
private LoadedType _loadedType;

/// <summary>
/// Initialize a task factory
/// </summary>
Expand All @@ -55,7 +50,7 @@ public void NullLoadInfo()
{
Assert.Throws<ArgumentNullException>(() =>
{
AssemblyTaskFactory taskFactory = new AssemblyTaskFactory();
AssemblyTaskFactory taskFactory = new();
taskFactory.InitializeFactory(null, "TaskToTestFactories", new Dictionary<string, TaskPropertyInfo>(), string.Empty, null, false, null, ElementLocation.Create("NONE"), String.Empty);
}
);
Expand Down Expand Up @@ -702,8 +697,8 @@ private void SetupTaskFactory(IDictionary<string, string> factoryParameters, boo
#else
_loadInfo = AssemblyLoadInfo.Create(typeof(TaskToTestFactories).GetTypeInfo().Assembly.FullName, null);
#endif
_loadedType = _taskFactory.InitializeFactory(_loadInfo, "TaskToTestFactories", new Dictionary<string, TaskPropertyInfo>(), string.Empty, factoryParameters, explicitlyLaunchTaskHost, null, ElementLocation.Create("NONE"), String.Empty);
Assert.True(_loadedType.Assembly.Equals(_loadInfo)); // "Expected the AssemblyLoadInfo to be equal"
TypeInformation typeInfo = _taskFactory.InitializeFactory(_loadInfo, "TaskToTestFactories", new Dictionary<string, TaskPropertyInfo>(), string.Empty, factoryParameters, explicitlyLaunchTaskHost, null, ElementLocation.Create("NONE"), String.Empty);
typeInfo.LoadInfo.ShouldBe(_loadInfo, "Expected the AssemblyLoadInfo to be equal");
}

#endregion
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 @@ -1170,7 +1170,7 @@ private void InitializeHost(bool throwOnExecute)
TaskBuilderTestTask.TaskBuilderTestTaskFactory taskFactory = new TaskBuilderTestTask.TaskBuilderTestTaskFactory();
taskFactory.ThrowOnExecute = throwOnExecute;
string taskName = "TaskBuilderTestTask";
(_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, loadedType, taskName, null);
(_host as TaskExecutionHost)._UNITTESTONLY_TaskFactoryWrapper = new TaskFactoryWrapper(taskFactory, new TypeInformation(loadedType), taskName, null);
_host.InitializeForTask
(
this,
Expand Down
50 changes: 19 additions & 31 deletions src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ void ITaskExecutionHost.InitializeForTask(IBuildEngine2 buildEngine, TargetLoggi

TaskRequirements requirements = TaskRequirements.None;

if (_taskFactoryWrapper.TaskFactoryLoadedType.HasSTAThreadAttribute())
if (_taskFactoryWrapper.TaskFactoryTypeInformation.HasSTAThreadAttribute)
{
requirements |= TaskRequirements.RequireSTAThread;
}

if (_taskFactoryWrapper.TaskFactoryLoadedType.HasLoadInSeparateAppDomainAttribute())
if (_taskFactoryWrapper.TaskFactoryTypeInformation.HasLoadInSeparateAppDomainAttribute)
{
requirements |= TaskRequirements.RequireSeparateAppDomain;

Expand Down Expand Up @@ -299,7 +299,7 @@ bool ITaskExecutionHost.InitializeForBatch(TaskLoggingContext loggingContext, It
if (_resolver == null)
{
_resolver = new TaskEngineAssemblyResolver();
_resolver.Initialize(_taskFactoryWrapper.TaskFactoryLoadedType.Assembly.AssemblyFile);
_resolver.Initialize(_taskFactoryWrapper.TaskFactoryTypeInformation.LoadInfo.AssemblyFile);
_resolver.InstallHandler();
}
#endif
Expand Down Expand Up @@ -899,15 +899,18 @@ private TaskFactoryWrapper FindTaskInRegistry(IDictionary<string, string> taskId
}
}

string taskFactoryFullName = returnClass.TaskFactory is AssemblyTaskFactory atf ? atf.TaskName : returnClass.TaskFactory.TaskType.FullName;
// Map to an intrinsic task, if necessary.
if (String.Equals(returnClass.TaskFactory.TaskType.FullName, "Microsoft.Build.Tasks.MSBuild", StringComparison.OrdinalIgnoreCase))
if (String.Equals(taskFactoryFullName, "Microsoft.Build.Tasks.MSBuild", StringComparison.OrdinalIgnoreCase))
{
returnClass = new TaskFactoryWrapper(new IntrinsicTaskFactory(typeof(MSBuild)), new LoadedType(typeof(MSBuild), AssemblyLoadInfo.Create(typeof(TaskExecutionHost).GetTypeInfo().Assembly.FullName, null)), _taskName, null);
AssemblyLoadInfo loadInfo = AssemblyLoadInfo.Create(typeof(TaskExecutionHost).GetTypeInfo().Assembly.FullName, null);
returnClass = new TaskFactoryWrapper(new IntrinsicTaskFactory(typeof(MSBuild)), new TypeInformation(new LoadedType(typeof(MSBuild), loadInfo)), _taskName, null);
_intrinsicTasks[_taskName] = returnClass;
}
else if (String.Equals(returnClass.TaskFactory.TaskType.FullName, "Microsoft.Build.Tasks.CallTarget", StringComparison.OrdinalIgnoreCase))
else if (String.Equals(taskFactoryFullName, "Microsoft.Build.Tasks.CallTarget", StringComparison.OrdinalIgnoreCase))
{
returnClass = new TaskFactoryWrapper(new IntrinsicTaskFactory(typeof(CallTarget)), new LoadedType(typeof(CallTarget), AssemblyLoadInfo.Create(typeof(TaskExecutionHost).GetTypeInfo().Assembly.FullName, null)), _taskName, null);
AssemblyLoadInfo loadInfo = AssemblyLoadInfo.Create(typeof(TaskExecutionHost).GetTypeInfo().Assembly.FullName, null);
returnClass = new TaskFactoryWrapper(new IntrinsicTaskFactory(typeof(CallTarget)), new TypeInformation(new LoadedType(typeof(CallTarget), loadInfo)), _taskName, null);
_intrinsicTasks[_taskName] = returnClass;
}
}
Expand Down Expand Up @@ -1073,30 +1076,15 @@ out parameterSet
else
{
// flag an error if we find a parameter that has no .NET property equivalent
if (_taskFactoryWrapper.TaskFactoryLoadedType.LoadedAssembly is null)
{
_taskLoggingContext.LogError
(
new BuildEventFileInfo( parameterLocation ),
"UnexpectedTaskAttribute",
parameterName,
_taskName,
_taskFactoryWrapper.TaskFactoryLoadedType.Type.Assembly.FullName,
_taskFactoryWrapper.TaskFactoryLoadedType.Type.Assembly.Location
);
}
else
{
_taskLoggingContext.LogError
(
new BuildEventFileInfo( parameterLocation ),
"UnexpectedTaskAttribute",
parameterName,
_taskName,
_taskFactoryWrapper.TaskFactoryLoadedType.LoadedAssembly.FullName,
_taskFactoryWrapper.TaskFactoryLoadedType.LoadedAssembly.Location
);
}
_taskLoggingContext.LogError
(
new BuildEventFileInfo( parameterLocation ),
"UnexpectedTaskAttribute",
parameterName,
_taskName,
_taskFactoryWrapper.TaskFactoryTypeInformation.LoadInfo.AssemblyName,
_taskFactoryWrapper.TaskFactoryTypeInformation.LoadInfo.AssemblyLocation
);
}
}
catch (AmbiguousMatchException)
Expand Down
37 changes: 30 additions & 7 deletions src/Build/Instance/ReflectableTaskPropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ namespace Microsoft.Build.Execution
internal class ReflectableTaskPropertyInfo : TaskPropertyInfo
{
/// <summary>
/// The reflection-produced PropertyInfo.
/// The name of the generated tasks.
/// </summary>
private PropertyInfo _propertyInfo;
private readonly string taskName;

/// <summary>
/// The type of the generated tasks.
/// Function for accessing information about a property on a task via its name.
/// </summary>
private Type _taskType;
private readonly Func<string, BindingFlags, PropertyInfo> getProperty;

/// <summary>
/// The reflection-produced PropertyInfo.
/// </summary>
private PropertyInfo _propertyInfo;

/// <summary>
/// Initializes a new instance of the <see cref="ReflectableTaskPropertyInfo"/> class.
Expand All @@ -35,7 +40,16 @@ internal ReflectableTaskPropertyInfo(TaskPropertyInfo taskPropertyInfo, Type tas
: base(taskPropertyInfo.Name, taskPropertyInfo.PropertyType, taskPropertyInfo.Output, taskPropertyInfo.Required)
{
ErrorUtilities.VerifyThrowArgumentNull(taskType, nameof(taskType));
_taskType = taskType;
getProperty = taskType.GetProperty;
taskName = taskType.FullName;
}

internal ReflectableTaskPropertyInfo(TaskPropertyInfo taskPropertyInfo, TypeInformation typeInformation)
: base(taskPropertyInfo.Name, taskPropertyInfo.PropertyType, taskPropertyInfo.Output, taskPropertyInfo.Required)
{
ErrorUtilities.VerifyThrowArgumentNull(typeInformation, nameof(typeInformation));
getProperty = typeInformation.GetProperty;
taskName = typeInformation.TypeName;
}

/// <summary>
Expand All @@ -52,6 +66,15 @@ internal ReflectableTaskPropertyInfo(PropertyInfo propertyInfo)
_propertyInfo = propertyInfo;
}

internal ReflectableTaskPropertyInfo(TypeInformation.PropertyInfo propertyInfo) :
base(
propertyInfo.Name,
propertyInfo.PropertyType,
propertyInfo.OutputAttribute,
propertyInfo.RequiredAttribute)
{
}

/// <summary>
/// Gets or sets the reflection-produced PropertyInfo.
/// </summary>
Expand All @@ -61,8 +84,8 @@ internal PropertyInfo Reflection
{
if (_propertyInfo == null)
{
_propertyInfo = _taskType.GetProperty(Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
ErrorUtilities.VerifyThrow(_propertyInfo != null, "Could not find property {0} on type {1} that the task factory indicated should exist.", Name, _taskType.FullName);
_propertyInfo = getProperty(Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
ErrorUtilities.VerifyThrow(_propertyInfo != null, "Could not find property {0} on type {1} that the task factory indicated should exist.", Name, taskName);
}

return _propertyInfo;
Expand Down
Loading