Error msb4018 the generatedepsfile task failed unexpectedly

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 SkiaSh...

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]

I tried to compile my new application in MonoDevelop and I got this error:

/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(5,5): Error MSB4018: The «GenerateDepsFile» task failed unexpectedly.
System.TypeLoadException: Could not load type of field ‘Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages’
(12) due to: Could not resolve type with token 01000027 from typeref
(expected class ‘NuGet.Packaging.Core.PackageIdentity’ in assembly
‘NuGet.Packaging, Version=5.0.0.6, Culture=neutral,
PublicKeyToken=31bf3856ad364e35’) assembly:NuGet.Packaging,
Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35
type:NuGet.Packaging.Core.PackageIdentity member:(null)
at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in :0
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute
() [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>: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 <58f0218f988743a48dd7c84cbe933f4e>:0 (MSB4018) (passcracker)

I cannot compile any application. Please help.

IAbstract's user avatar

IAbstract

19.5k15 gold badges96 silver badges144 bronze badges

asked Apr 23, 2019 at 7:14

d3ds1r's user avatar

I had the same problem using .Net Standard 2.1, and I solved it for myself by cleaning the solution and then rebuilding it.

answered Oct 27, 2019 at 20:00

Overlord's user avatar

OverlordOverlord

2,6702 gold badges18 silver badges22 bronze badges

2

Just moved my projects to a new machine (copying, not pulling from GIT) and started getting this. Deleting the bin and obj folders in each project solved this issue.

answered Feb 4, 2020 at 9:03

brenwebber's user avatar

brenwebberbrenwebber

3553 silver badges6 bronze badges

2

Your combination of Mono MSBuild and .NET Core SDK is incompatible because they use different versions of the internal NuGet library. To resolve this problem, you can:

  • Downgrade .NET Core SDK to 2.1.5xx or 2.2.1xx (for example, 2.1.505 or 2.2.108)
  • Upgrade Mono to 6.0

You can find a detailed explanation of this problem and possible solutions here: https://rider-support.jetbrains.com/hc/en-us/articles/360004180039

answered Jul 10, 2019 at 16:56

AndreyAkinshin's user avatar

AndreyAkinshinAndreyAkinshin

18.2k29 gold badges95 silver badges153 bronze badges

This appears to be a known issue.

The only fix at this stage seems to be to downgrade to .NET Core v2.2.105.

To downgrade:

  • Uninstall the latest .NET Core version (v2.2.2+).
  • Download and install v2.2.105.

answered Apr 30, 2019 at 4:39

André Haupt's user avatar

André HauptAndré Haupt

3,1725 gold badges32 silver badges54 bronze badges

4

Run the following CMD in the *.sln folder. This will delete all your OBJ and BIN folders automatically. And your issue will be solved.

FOR /d /r . %%d in (bin,obj) DO ( IF EXIST "%%d" ( ECHO %%d | FIND /I "node_modules" > Nul && ( ECHO.Skipping: %%d ) || ( ECHO.Deleting: %%d rd /s/q "%%d" )))

answered Sep 23, 2021 at 11:38

Alper Ebicoglu's user avatar

Alper EbicogluAlper Ebicoglu

8,6521 gold badge47 silver badges52 bronze badges

I had the same problem in migration from .Net Framework 4.5 to .NET 6.0 (with the 70 project).

All of the above answers are correct, but they were not enough for my problem.

I use this answer:

Deleting the bin and obj and .vs folders then Clean Solution and
Rebuild Solution

it’s working in Build Mode, not Rebuild. And the problem remained.

I update the Version of SDK , but not enough and I have the problem.

I realized this:

duplicate property (or variables) with the same name (or similar Name) in derived classes.

It was a good solution and a few problems were solved.

finally (after the 3 days), The biggest problem I noticed was that I had Loop References.

I fixed The Loop References in projects and the error is solved.

answered May 7, 2022 at 12:28

AminRostami's user avatar

AminRostamiAminRostami

2,5363 gold badges24 silver badges45 bronze badges

Change the name of the file. For instance, Add prefix _ or #; so, it cannot be used.

Restart Visual Studio, then try to build. If still problem is there, needs to restart the machine.

answered Sep 19, 2019 at 13:45

Rohil Patel's user avatar

Rohil PatelRohil Patel

3563 silver badges8 bronze badges

I had this error happen and the slove for me was correcting the Package version number in .csproj file .

   <Version>2.0.7.</Version> <!--casued the error-->

   <Version>2.0.7</Version> <!--this fixed the error-->

Removing the trailing ‘.’ fixed this for me.

answered Sep 20, 2019 at 18:10

Luke Hammer's user avatar

Luke HammerLuke Hammer

1,9663 gold badges16 silver badges31 bronze badges

I had .net standard project built on .net standard 2.0. Yesterday I updated my Visual Studio 2019 to 16.3.0 to leverage .Net Core 3.0. But all of sudden build of project targeting on standard 2.0 started throwing «GenerateDepsFile» task failed unexpectedly error.

I was able to resolve this issue by changing the target framework to 2.1.

answered Sep 26, 2019 at 5:30

Krishnaraj Barvathaya's user avatar

If you have <DelaySign>false</DelaySign> in your .csproj file remove it to solve this Problem.

answered Feb 10, 2021 at 13:38

Danial Delkhosh's user avatar

in vs code i got this error, after trying some solution from forms, i found solution in deleting bin and obj foldersfrom project and build again.
this solved my problem.
vs code version: 1.53.1
dotnet version : 5

answered Feb 11, 2021 at 10:01

kargarf's user avatar

I had it after updating vs 2019 community,
Delete bin & obj folders,
then clean & build the solution.

answered Sep 26, 2021 at 12:11

Mahmoud.Ismail's user avatar

I had this error and after reading comments, I was able to resolve by combining comments — First deleted bin folder, obj folder, executed clean command, deleted enter image description here and then rebuilded.

answered Dec 15, 2022 at 16:23

Riddhi Shah's user avatar

1

I recently ran into a compilation error that is preventing me from building and running my WebAPI. It was working perfectly just the night before, so I’m very confused as to why it’s happening now with no changes. My target framework is «netcoreapp3.1». Additionally, when I do build and run the API, I receive

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies
Common solutions to this issue:
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
Specific error detected by ANCM:
A JSON parsing exception occurred in [C:UsersusernamesourcereposMainLibrariesWebAPIWebAPIbinDebugnetcoreapp3.1WebAPI.deps.json]: * Line 1, Column 2 Syntax error: Malformed token Error initializing the dependency resolver: An error occurred while parsing: C:UsersusernamesourcereposMainLibrariesWebAPIWebAPIbinDebugnetcoreapp3.1WebAPI.deps.json

This is the full error log:

1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly.
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018: System.ArgumentException: An item with the same key has already been added.
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WritePortableTarget(IReadOnlyList`1 runtimeLibraries, IReadOnlyList`1 compilationLibraries)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WriteTargets(DependencyContext context)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.Write(DependencyContext context)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Extensions.DependencyModel.DependencyContextWriter.Write(DependencyContext context, Stream stream)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath)
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore()
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:Program Filesdotnetsdk3.1.402SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets(194,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

What I have tried:

Things I've tried:

Repairing VS
Reinstalling VS
Deleting bin and obj
Deleting .vs from my solutions folder

  • Remove From My Forums
  • Question

  • I have a Smart Device application that is generating the following errror when I attempt to build.  I would appreciate any feedback in how to debug this error, or what might be a typical cause of this problem. 

    C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets(1616,9): error MSB4018: The «GenerateResource» task failed unexpectedly.

    C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets(1616,9): error MSB4018: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

    C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.Shared.ExceptionHandling.RethrowUnlessFileIO(Exception e)

    C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.NeedSeparateAppDomain()

    C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.Execute()

    C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets(1616,9): error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteTask(ExecutionMode howToExecuteTask, Hashtable projectItemsAvailableToTask, BuildPropertyGroup projectPropertiesAvailableToTask, Boolean& taskClassWasFound)

    Done building project «PromoScan.vbproj» — FAILED.

Answers

  • Hi,

    We know this problem and we are tracking this as an issue that needs fixing. In the mean time can you try this workaround and tell us if it resolves the problem for you?

    Edit your project file and add this to the first PropertyGroup:

       <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies>

    That should get rid of this error. Tell us what you find.

    Faisal Mohamood | Program Manager | Visual Studio — MSBuild

  • Faisal,

    u r a champion.It works for me.

    Thanks very much.

    Cheers

    Chandra

I tried to compile my new application in MonoDevelop and I got this error:

/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(5,5): Error MSB4018: The «GenerateDepsFile» task failed unexpectedly.
System.TypeLoadException: Could not load type of field ‘Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages’
(12) due to: Could not resolve type with token 01000027 from typeref
(expected class ‘NuGet.Packaging.Core.PackageIdentity’ in assembly
‘NuGet.Packaging, Version=5.0.0.6, Culture=neutral,
PublicKeyToken=31bf3856ad364e35’) assembly:NuGet.Packaging,
Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35
type:NuGet.Packaging.Core.PackageIdentity member:(null)
at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in :0
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute
() [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>: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 <58f0218f988743a48dd7c84cbe933f4e>:0 (MSB4018) (passcracker)

I cannot compile any application. Please help.

11 Answers

I had the same problem using .Net Standard 2.1, and I solved it for myself by cleaning the solution and then rebuilding it.

Just moved my projects to a new machine (copying, not pulling from GIT) and started getting this. Deleting the bin and obj folders in each project solved this issue.

Your combination of Mono MSBuild and .NET Core SDK is incompatible because they use different versions of the internal NuGet library. To resolve this problem, you can:

  • Downgrade .NET Core SDK to 2.1.5xx or 2.2.1xx (for example, 2.1.505 or 2.2.108)
  • Upgrade Mono to 6.0

You can find a detailed explanation of this problem and possible solutions here: https://rider-support.jetbrains.com/hc/en-us/articles/360004180039

This appears to be a known issue.

The only fix at this stage seems to be to downgrade to .NET Core v2.2.105.

To downgrade:

  • Uninstall the latest .NET Core version (v2.2.2+).
  • Download and install v2.2.105.

Change the name of the file. For instance, Add prefix _ or #; so, it cannot be used.

Restart Visual Studio, then try to build. If still problem is there, needs to restart the machine.

I had this error happen and the slove for me was correcting the Package version number in .csproj file .

   <Version>2.0.7.</Version> <!--casued the error-->

   <Version>2.0.7</Version> <!--this fixed the error-->

Removing the trailing ‘.’ fixed this for me.

I had .net standard project built on .net standard 2.0. Yesterday I updated my Visual Studio 2019 to 16.3.0 to leverage .Net Core 3.0. But all of sudden build of project targeting on standard 2.0 started throwing «GenerateDepsFile» task failed unexpectedly error.

I was able to resolve this issue by changing the target framework to 2.1.

If you have <DelaySign>false</DelaySign> in your .csproj file remove it to solve this Problem.

in vs code i got this error, after trying some solution from forms, i found solution in deleting bin and obj foldersfrom project and build again.
this solved my problem.
vs code version: 1.53.1
dotnet version : 5

Run the following CMD in the *.sln folder. This will delete all your OBJ and BIN folders automatically. And your issue will be solved.

FOR /d /r . %%d in (bin,obj) DO ( IF EXIST "%%d" ( ECHO %%d | FIND /I "node_modules" > Nul && ( ECHO.Skipping: %%d ) || ( ECHO.Deleting: %%d rd /s/q "%%d" )))

I had it after updating vs 2019 community,
Delete bin & obj folders,
then clean & build the solution.

Describe the bug

Trying to compile the solution fails at the GenerateDepsFile Task
GitHub to solution (very simple console app with only a few writelines https://github.com/HamburgerPlsdotexe/AutomatedPlanner

Both Costura and Fody are the latest versions:
5.7.0 and 6.6.3 respectively

To Reproduce

Compile

Exceptions (if any)

Severity Code Description Project File Line Suppression State
Error MSB4018 The «GenerateDepsFile» task failed unexpectedly.
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WritePortableTarget(String key, IReadOnlyList1 runtimeLibraries, IReadOnlyList`1 compilationLibraries, Utf8JsonWriter jsonWriter)
at Microsoft.Extensions.DependencyModel.DependencyContextWriter.WriteTargets(DependencyContext context, Utf8JsonWriter jsonWriter)
at Microsoft.Extensions.DependencyModel.DependencyContextWriter.Write(DependencyContext context, Stream stream)
at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath)
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.NET.Build.Tasks.TaskWithAssemblyResolveHooks.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() AutomatedPlanner C:Program Filesdotnetsdk6.0.300SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets 176

Further technical details

  • PS D:AutomatedPlanner> dotnet —info
    .NET SDK (reflecting any global.json):
    Version: 6.0.300
    Commit: 8473146

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:Program Filesdotnetsdk6.0.300

Host (useful for support):
Version: 6.0.5
Commit: 70ae3df4a6

.NET SDKs installed:
6.0.202 [C:Program Filesdotnetsdk]
6.0.300 [C:Program Filesdotnetsdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.17 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.4 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.17 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App]

  • VS 2022, version 4.8.04084

This issue happens whenever I add the dll of the solution in to the references through «browse»

However, once removed, the program still doesn’t seem to run just as a standalone .exe

Facing this issue while publish/Build of the project 

Severity Code Description Project File Line Suppression State

Error MSB4018 The «GenerateDepsFile» task failed unexpectedly.

System.IO.FileNotFoundException: C:Usersrkaushik.nugetpackagesmicrosoft.teamfoundationserver.client15.131.1libnet45Microsoft.TeamFoundation.Build.Client.dll

at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)

at Microsoft.NET.Build.Tasks.FileUtilities.GetFileVersion(String sourcePath)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.CreateRuntimeFile(String path, String fullPath)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.CreateRuntimeFile(LockFileTargetLibrary library, LockFileItem item)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.<>c__DisplayClass40_0.<CreateRuntimeAssemblyGroups>b__0(LockFileItem a)

at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()

at System.Linq.Buffer`1..ctor(IEnumerable`1 source)

at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.CreateRuntimeAssemblyGroups(LockFileTargetLibrary targetLibrary, SingleProjectInfo referenceProjectInfo)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.GetLibrary(LockFileTargetLibrary export, LockFileLookup libraryLookup, IDictionary`2 dependencyLookup, Boolean runtime)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.<>c__DisplayClass36_0.<GetLibraries>b__0(LockFileTargetLibrary export)

at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()

at System.Linq.Enumerable.<CastIterator>d__97`1.MoveNext()

at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()

at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()

at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()

at System.Linq.Buffer`1..ctor(IEnumerable`1 source)

at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)

at Microsoft.Extensions.DependencyModel.DependencyContext..ctor(TargetInfo target, CompilationOptions compilationOptions, IEnumerable`1 compileLibraries, IEnumerable`1 runtimeLibraries, IEnumerable`1 runtimeGraph)

at Microsoft.NET.Build.Tasks.DependencyContextBuilder.Build()

at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore()

at Microsoft.NET.Build.Tasks.TaskBase.Execute()

at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()

at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() TFSBusinessLogicAPI C:Program Filesdotnetsdk2.1.500SdksMicrosoft.NET.SdktargetsMicrosoft.NET.Sdk.targets 129

Понравилась статья? Поделить с друзьями:
  • Error msb3073 ue4
  • Error msb3073 the command setlocal
  • Error msb3073 the command npm run build exited with code 1
  • Error msb3073 the command npm install exited with code 127
  • Error msb3073 cmake