I am trying to run a simple task after build in a .NET Core console app.
Here is my cspoj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" />
</ItemGroup>
<UsingTask TaskName="SimpleTask" AssemblyFile = "bin\Debug\netcoreapp3.1\ConsoleApp10.dll">
</UsingTask>
<Target Name="MyTarget" AfterTargets="Build">
<SimpleTask/>
</Target>
</Project>
And here is the task class:
using Microsoft.Build.Utilities;
namespace ConsoleApp10.MyTasks
{
public class SimpleTask : Task
{
public override bool Execute()
{
Log.LogWarning("warning message");
return true;
}
public string MyProperty { get; set; }
}
}
But I am getting the following error:
Error MSB4018 The "SimpleTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at ConsoleApp10.MyTasks.SimpleTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
I could not figure out what the problem is.