46

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
  • 19,551
  • 15
  • 98
  • 146
d3ds1r
  • 461
  • 1
  • 4
  • 3

14 Answers14

95

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

Overlord
  • 2,740
  • 2
  • 18
  • 22
  • 2
    I deleted all existing packages from **C:\Users\YourUserName\.nuget\packages**. Please note that there is dot before "nuget". Tried rebuilding and it worked. – Vikram Singh Saini Aug 07 '20 at 07:35
  • 1
    @code_disciple that made me chuckle, thanks! On a serious note, the clean and rebuild worked for me. – Ben Power Nov 02 '20 at 22:48
21

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.

brenwebber
  • 365
  • 3
  • 6
  • 2
    Worked for me in vs2019 .net core 3.1 – TabsNotSpaces Sep 30 '20 at 17:31
  • 1
    You might run a "Restore NUGET Packages" on the solution after that, either by right-clicking on the solution and selecting the command or via CLI: `nuget restore MySolution.sln` – Matt Jan 22 '21 at 11:59
5

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

AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
3

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:

André Haupt
  • 3,294
  • 5
  • 32
  • 57
  • Just for others who find this post, I'm using VS for Mac 7.7.4, I had to delete the dotnet sdk from '/usr/local/share/dotnet/sdk' manually and install v2.2.107 (x64) from the above provided link. This version is the only one that did not throw any error for me – Ahs N Jun 20 '19 at 03:38
  • Adding this to the list that still fails : /usr/share/dotnet/sdk/2.2.300/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(5,5): Error MSB4018: The "GenerateDepsFile" task failed unexpectedly. – granadaCoder Jul 04 '19 at 07:57
  • 1
    Ubuntu 18.04 install of 2.2.105 link : https://dotnet.microsoft.com/download/linux-package-manager/ubuntu18-04/sdk-2.2.105 – granadaCoder Jul 04 '19 at 08:03
  • 1
    After using that microsoft link, the "install" command line failed (I still needed the setup commands listed at the article). But this command finally worked : sudo apt install dotnet-sdk-2.2=2.2.105-1 – granadaCoder Jul 04 '19 at 16:20
2

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.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 21 '22 at 22:24
  • @Community this is a pretty silly comment, they've included an image that didn't work due to their rep < 50 and now you're saying edit it to make it better?!! – Jeremy Thompson Jun 06 '23 at 04:30
1

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" )))
Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
1

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.

AminRostami
  • 2,585
  • 3
  • 29
  • 45
0

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.

Rohil Patel
  • 386
  • 3
  • 8
0

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.

Luke Hammer
  • 2,076
  • 3
  • 18
  • 31
0

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.

0

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

Danial Delkhosh
  • 147
  • 1
  • 9
0

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

kargarf
  • 51
  • 4
0

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

0

I had a project that somehow was referencing its own dll from another project bin file. I have no idea how it was generated

<ItemGroup>
  <Reference Include="PBS.Hypercomb.Model">
    <HintPath>..\PBS.Hypercomb.Services\bin\Debug\net6.0-windows\PBS.Hypercomb.Model.dll</HintPath>
  </Reference>
</ItemGroup>

This was within PBS.Hypercomb.Model project. Removing it seems to have fixed it.

jwize
  • 4,230
  • 1
  • 33
  • 51