NitinSingh
NitinSingh

Reputation: 2068

.NET Core solution build gives a GenerateDepsFile error

Environment

Problem Context

When the solution is build, a "GenerateDepsFile:" error is given by MS Build for a particular project in the solution. It tries to add an item to a dictionary when it already exists, but not which dictionary it is trying or what duplicate key is being attempted.

Exploration Performed

Upvotes: 0

Views: 4844

Answers (3)

Anuj Rajvansh
Anuj Rajvansh

Reputation: 11

The "GenerateDepsFile" task failed unexpectedly.

I believe You just need to delete the bin and obj folder and then Clean and Rebuild solution.

this should work, It work for me after going through many approaches.

Edit:

This worked for me as well where as a Clean Solution didn't. Please take a backup of your bin & obj folders before you delete them as there are rare scenario's where this could back fire on you and cost you a lot of work.

Upvotes: 1

NitinSingh
NitinSingh

Reputation: 2068

After lots of exploration, it looked like a multi version NuGet package scenario (cleaned the NuGet cache already)

Finally I went to all child projects and validated if the same version of all NuGet package is being used across. It turned out that the version of some assemblies ( esp Microsoft.Data.SqlClient) were different in child projects and the calling project. Since the projects themselves were building all fine, this was not reported on project level, but when those DLLs were getting consumed in parent one, it start giving the error.

It turned out the child projects were built a while back with the latest version available at that time. The parent project was just referencing the DLLs from the output folder and was not aware of previous version and got its own version updated..

So, do ensure that when a particular version of NuGet is approved at one place, that gets updated across the whole eco-system!

However MS should update the error to at least point what dictionary is failing with what specific key in the main message as its very hard to debug with the verbose log.

Upvotes: 3

Mr Qian
Mr Qian

Reputation: 23715

The "GenerateDepsFile" task failed unexpectedly is too large and you should check its detailed build log to judge what is the real problem.

Under Tools-->Options-->Projects and Solutions-->Build and Run--> set MSBuild project build output verbosity to Detailed and then build again to get its detailed log.

Also, you can share the detailed error build log here with us.

Maybe you could check these suggestions:

1) clean nuget caches or just delete all cache file under C:\Users\xxx\.nuget\packages.

2) do not forget to delete .vs hidden folder under the solution folder, bin, obj folder of the project, and then use dotnet restore command or msbuild -t:restore command to restore these files.

3) update VS2019 to the latest 16.8.4 and your Net Core 3.1 Sdk to the latest 3.1.11.

Upvotes: 2

Related Questions