dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

MSB4018: The "GenerateDepsFile" task failed unexpectedly. #3376

Open mattleibow opened 5 years ago

mattleibow commented 5 years ago

I am trying to use Ubuntu 18.04 to test some things, and I can use any of the newer .NET Core SDKs.

I just installed a fresh VM with 18.04, and installed my usual tools. I then try and build SkiaSharp, and then the .NET Standard projects and Tizen fail to build with the same error.

I can roll back to dotnet-sdk-2.1.105, and that seems to work fine. As soon as I go later, then it fails. I tried installing a different version of dotnet 2.2, but I only have one for some reason. Sure, I could install it manually and all that. But, who wants to do that - and I am not even sure it is going to work.

Here is my apt-search output: https://gist.github.com/mattleibow/935de7d22b24cfcf3ae9ab0c16b1908f

What is the reason for these failures? My code was working - as it is building just fine with 2.1.105, and then I bump up just a fraction and boom?

Build Errors:

/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.NetStandard/SkiaSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.NetStandard/SkiaSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <a7945d89c0ac41f8a1c76203a2991e34>:0  [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.NetStandard/SkiaSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.NetStandard/SkiaSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   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 <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.NetStandard/SkiaSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.NetStandard/HarfBuzzSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.NetStandard/HarfBuzzSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <a7945d89c0ac41f8a1c76203a2991e34>:0  [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.NetStandard/HarfBuzzSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.NetStandard/HarfBuzzSharp.NetStandard.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   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 <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.NetStandard/HarfBuzzSharp.NetStandard.csproj]

...

/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.Tizen/SkiaSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.Tizen/SkiaSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <a7945d89c0ac41f8a1c76203a2991e34>:0  [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.Tizen/SkiaSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.Tizen/SkiaSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   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 <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/SkiaSharp.Tizen/SkiaSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.Tizen/HarfBuzzSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.Tizen/HarfBuzzSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <a7945d89c0ac41f8a1c76203a2991e34>:0  [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.Tizen/HarfBuzzSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.Tizen/HarfBuzzSharp.Tizen.csproj]
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   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 <58f0218f988743a48dd7c84cbe933f4e>:0  [/media/matthew/Projects/SkiaSharp/binding/HarfBuzzSharp.Tizen/HarfBuzzSharp.Tizen.csproj]
livarcocc commented 5 years ago

Do you have environment variable MSBuildSDKsPath or MSBuildExtensionsPath set by any change? It seems like it is possible that your 2.2.300 SDK is loading 2.1.700 props/targets, as show above. This usually happens when folks set the PATH to the SDK manually using the environment variables above.

AndreyAkinshin commented 5 years ago

@mattleibow if you are using Mono MSBuild, then you probably have incompatible versions of Mono MSBuild and .NET Core SDK. The problem and possible solutions are described here: https://rider-support.jetbrains.com/hc/en-us/articles/360004180039

mattleibow commented 5 years ago

I have been looking at this error for over a week now and I think the whole .NET Core thing is broken. I am using mono 5.20 and msbuild 16.0. The only version of .NET Core that works is the 2.2.1xx series.

So I figured that if I install .NET Core 2.2.107 (and only that) and set the global.json to 2.2.107, then it would work, right? Well no, I get this error:

error MSB4018: The "GenerateDepsFile" task failed unexpectedly.
/usr/share/dotnet/sdk/2.2.107/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): 
    error MSB4018: System.MissingMethodException: Method not found: 
        System.Collections.Generic.IList`1<NuGet.Packaging.Core.PackageDependency> NuGet.ProjectModel.LockFileTargetLibrary.get_Dependencies()

So I tried a few things, still no joy. But suddenly it started working. I thought I had done it. When reviewing my PR I found that I had forgotten to update my global.json to match my install version. I was using 2.2.108 in the global.json and the installed version of 2.2.107.

I get this message at the start of msbuild:

A compatible installed dotnet SDK for global.json version: [2.2.108] from [/home/matthew/Projects/SkiaSharp/global.json] was not found
Please install the [2.2.108] SDK or update [/home/matthew/Projects/SkiaSharp/global.json] with an installed dotnet SDK:
  2.1.700 [/usr/share/dotnet/sdk]
  2.2.107 [/usr/share/dotnet/sdk]

But, the build succeeds. In fact, I can stick ANY 2.2.1xx in the global.json, and as long as it DOES NOT match the .NET Core installed, it works. I even threw a curve ball with a 2.2.199 and that works.

If I delete the global.json, then the build fails again.

I tried all this as well with .NET Core 2.2.105 installed and 2.2.107 in the global.json and that works. Seems to be something wrong with the versions.

I would LOVE to use any of the 2.2.2xx+, but unfortunately that requires VS 2019, which is not possible at the moment because they dropped support for older Windows 10 SDKs. And, as this release that I am trying to build is a patch release, I don't really want to switch to an entirely different system and/or drop any support for anything.

mattleibow commented 5 years ago

Thanks @AndreyAkinshin for the info and link, I was able to resolve a few other errors to get me to this place.

mattleibow commented 5 years ago

I just noticed that I can't actually use a version number of 2.2.199 because then dotnet operations fail. Seems to work again if I use 2.2.108.1. I get a warning on macOS and Linux about the invalid version, but it still goes. Windows just works, no warnings.

livarcocc commented 5 years ago

I am not sure where you are getting version of the .NET Core SDK 2.2.199 and 2.2.108.1. These are not versions shipped by the .NET Core SDK team.

And @AndreyAkinshin is correct. The versions of these components are not all mix and match. They need to match. In your case, 2.2.100 is equivalent of VS 15.9. Not sure what version of Mono would be equivalent to that though.

mattleibow commented 5 years ago

@livarcocc I am just making up numbers 2.2.199 and 2.2.108.1 just to be able to build. If I use real version numbers, then it doesn't.

livarcocc commented 5 years ago

@mattleibow I don't follow why are you coming up with random version numbers at all. That should really not be the solution to whatever problem you are running into.

From the original description of the issue, this happens because you are using a .NET Core SDK version with versions or Mono and MSbuild that it is not really compatible with.

mattleibow commented 5 years ago

That is the thing. I have set up all the versions to be correct on devops and so it should work. But it doesn't. Unless I make up a random version in the global.json.

livarcocc commented 5 years ago

Can you share the output of dotnet --info in the devops machine?

I suspect the bogus global.json might be forcing a particular SDK to be picked that happens to work.

AJIOB commented 3 years ago

Do you have any updates?

I have the same issue on a 24-core CPU on CI. Environment: Gitlab Runner 13.10.0 on Ubuntu 18.04 LTS. Using docker image sha256:82e2a34647f0a8a8bf83c2cc2e80fd4a4149a702b696ac18c838c725662303ad for mcr.microsoft.com/dotnet/sdk:3.1 with digest mcr.microsoft.com/dotnet/sdk@sha256:72cdb39fe665873fef8dba77a9000ff6d1d57dde8f2fe64d04ed799b6e0e62ae.