Reputation: 1
I got a simple task:
namespace MyLibs
{
public class MyTask : Microsoft.Build.Utilities.Task
{
public override bool Execute()
{
Console.WriteLine("Task");
return true;
}
}
}
Then I tried to use them in .csproj
. It's simple as well:
<Project>
.....
<UsingTask TaskName="$(AssemblyName).MyTask" AssemblyName="$(AssemblyName)"/>
<Target Name="PostBuild2" AfterTargets="PostBuildEvent">
<MyTask/>
</Target>
</Project>
When I built, I got this:
C:\Code\ConsoleTest\MyLibs\MyLibs.csproj(164,9): error MSB4062: The "MyLibs.MyTask" task could not be loaded from the assembly MyLibs. Could not load file or assembly 'MyLibs, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. C onfirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Then tried to use AssemblyFile
instead:
namespace MyLibs
{
public class MyTask1 : Microsoft.Build.Utilities.Task
{
public override bool Execute()
{
Console.WriteLine("Task1");
return true;
}
}
public class MyTask2 : Microsoft.Build.Utilities.Task
{
public override bool Execute()
{
Console.WriteLine("Task2");
return true;
}
}
}
<Project>
.....
<UsingTask TaskName="$(AssemblyName).MyTask1" AssemblyFile="$(TargetPath)"/>
<Target Name="PostBuild1" AfterTargets="PostBuildEvent">
<MyTask1/>
</Target>
<UsingTask TaskName="$(AssemblyName).MyTask2" AssemblyName="$(AssemblyName)"/>
<Target Name="PostBuild2" AfterTargets="PostBuild1">
<MyTask2/>
</Target>
</Project>
Looking at the result of the build, AssemblyFile
works, but AssemblyName
still doesn't work. How does UsingTask work with AssemblyName?
Task1
C:\Code\ConsoleTest\MyLibs\MyLibs.csproj(169,9): error MSB4062: The "MyLibs.MyTask2" task could not be loaded from the assembly MyLibs. Could not load file or assembly 'MyLibs, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. C onfirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Upvotes: 0
Views: 155