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=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=188.8.131.52, 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
Microsoft.PackageDependencyResolution.targets(234, 5): [MSB4018] The "ResolvePackageAssets" task failed unexpectedly.
System.MissingMethodException: Method not found: System.Collections.Generic.IList`1<string> NuGet.ProjectModel.LockFileTargetLibrary.get_FrameworkReferences()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter.WriteItemGroup (System.Action writeItems) [0x0000e] in <465433aecc4e4125ae090de9fa6902e7>:0
at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter.WriteItemGroups () [0x0005a] in <465433aecc4e4125ae090de9fa6902e7>:0
at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter.Write () [0x00006] in <465433aecc4e4125ae090de9fa6902e7>:0
How to resolve the problem
There are three primary known ways to resolve this problem depending on your current environment and solution configuration.
If your projects do not target the full .NET Framework (e.g., net46 or net472)
In case all of your projects do not target the full .NET Framework, for example, all of your csproj files contain the following:
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 have at least one csproj file in your solution which targets .NET Framework like this
please use one of the further described ways.
If you use mono 5.x and you want to continue using it
In case, 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 (for example, 2.1.505 or 2.2.108).
In order to check installed .NET Core SDK versions on your machine, you can use the following command:
an output example:
If you discovered that you do not have a necessary version, follow the link and install SDK. If you do have compatible SDK on your machine, follow one of the options described below to change the currently used SDK version.
Option 1. Changing the .NET Core SDK version using global.json file
Option 2. Uninstalling later versions
- check that necessary .NET Core version is installed on your machine (as was described above).
- remove all the versions which are higher than the necessary one. For example, if you have 2.2.100, 2.2.200, 2.2.300 installed you have to uninstall 2.2.200 and 2.2.300.
- restart Rider
In order to check that now you are using the correct version of .NET Core SDK you can open the solution directory in the terminal and run the command:
Please remember 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 and you want to keep using it
In case you use one of the latest version 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 according to the following list of compatible mono versions:
- if you use mono 5.18.1.* you should upgrade it up to 184.108.40.206+
- if you use mono 5.20.1.*you should upgrade it up to 220.127.116.11+
- or you can install mono 6.0+
In order to check the currently installed mono version use the command
If you have several mono versions installed you can select an MSBuild from the corresponding mono via the Rider settings "File | Settings | Build, Execution, Deployment | Toolset and Build | Use MSBuild version."
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.
- 18.104.22.168: 4.3
- 22.214.171.1240+: 4.7
- 5.14+: 4.7
- 126.96.36.199 - 188.8.131.52: 4.7
- 184.108.40.206+: 4.8
- 220.127.116.11 - 18.104.22.168: 4.8
- 22.214.171.124+ : 5.0
- 126.96.36.199: 4.8
- 188.8.131.52+: 5.0
- 6.0+: 5.0
You can find more details here: