Incompatible versions of Mono MSBuild and .NET Core SDK (MSB4018)

Some combinations of the Mono MSBuild and .NET Core SDK are incompatible on Linux and macOS.

If you use such combinations, it will be impossible to build your project in JetBrains Rider or the terminal.

Instead of a successful build, you will get an error like this:

Microsoft.NET.Sdk.targets(124, 5): [MSB4018] The "GenerateDepsFile" task failed unexpectedly.
System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (13) due to: Could not resolve type with token 01000020 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null)
at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <9524e6fbf1724027a475d15b01fab866>:0
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <7b80049ba212460da3a78bdfcc799ef4>:0
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x001f6] in <7b80049ba212460da3a78bdfcc799ef4>:0

For example, if you use Mono 5.16 and 5.18, you may experience this problem with .NET Core SDK 3 Preview 3. However, it will work fine with .NET Core SDK 3 Preview 1, 2, and .NET Core SDK 2.1.403.

To resolve this problem, you can try the following:

  • Change the MSBuild version in the current toolset (File | Settings | Build, Execution, Deployment | Toolset and Build | Use MSBuild version) to MSBuild from .NET Core SDK.
  • Upgrade or downgrade the installed version of .NET Core SDK or Mono

You can find more details here:

Please sign in to leave a comment.

Have more questions?

Submit a request