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

Problem description

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=5.0.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.0.0.4, 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

How to resolve the problem

If your projects do not target the full .NET Framework (e.g., net46 or net472), you need to change MSBuild version in settings "File | Settings | Build, Execution, Deployment | Toolset and Build | Use MSBuild version" to MSBuild from .NET Core SDK (e.g., /usr/local/share/dotnet/sdk/2.2.100/MSBuild.dll).

If you use mono 5.x and you want to continue using it, you need to change the .NET Core SDK version. It is recommended to use .NET Core SDK 2.1.5xx or 2.2.1xx.

Note that .NET Core SDK 2.1.600+, 2.2.200+, and 3.0.100+ (including preview versions) are not compatible with mono 5.x.

If you use one of the latest versions of .NET Core SDK (2.1.600+, 2.2.200+, and 3.0.100+) and you want to keep using it, you should upgrade your mono version to 6.0+ (this version has not been released at the time this article was published).

Technical details

Below you can see the mapping from different .NET Core SDK versions to the corresponding embedded NuGet assembly versions.

  • 2.1.5xx: 4.9.0
  • 2.1.6xx: 5.0.0
  • 2.1.7xx: 5.1.0
  • 2.2.1xx: 4.9.x
  • 2.2.2xx: 5.0.0
  • 2.2.3xx: 5.1.0
  • 3.0.100-preview-009812: 5.0.0-preview.1
  • 3.0.100-preview-010184: 5.0.0-preview.1
  • 3.0.100-preview3-010431: 5.0.0-rtm
  • 3.0.100-preview4-011223: 5.1.0
  • 3.0.100-preview5-011568: 5.1.0
  • 3.0.100-preview6-012264: 5.2.0-preview2

And here you can see the mapping from different Mono versions to the corresponding embedded NuGet assembly versions which are included in MSBuild.

  • 5.12: 4.7
  • 5.14: 4.7
  • 5.16: 4.8
  • 5.18: 4.8
  • 5.20: 4.8
  • 6.0: 5.0 

References

You can find more details here:

1 comment

I'm using Linux with Mono 5.20 and dotnet 2.2 but I was receiving this error. What fixed my problem was to install the archived version (2.1.505) for dotnet.

 

 

 

0

Please sign in to leave a comment.

Have more questions?

Submit a request