36

I am trying to set up visual studio 2019 on macos (10.14.3), but when attempting to build a default web MVC project I get this dependency error:

    Target _CheckForNETCoreSdkIsPreview:
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
Target ResolvePackageAssets:
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly.
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018: System.TypeLoadException: Could not resolve type with token 0100003f from typeref (expected class 'NuGet.Packaging.Core.PackageDependency' in assembly 'NuGet.Packaging, Version=5.0.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter.GetPlatformPackageExclusions () [0x000d7] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter..ctor (Microsoft.NET.Build.Tasks.ResolvePackageAssets task, System.IO.Stream stream) [0x0009b] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheReader.CreateReaderFromDisk (Microsoft.NET.Build.Tasks.ResolvePackageAssets task, System.Byte[] settingsHash) [0x0003a] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheReader..ctor (Microsoft.NET.Build.Tasks.ResolvePackageAssets task) [0x00015] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups () [0x00000] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore () [0x00018] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-10/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:573 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,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) [0x00212] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-10/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:784 
Done building target "ResolvePackageAssets" in project "TestingApp.csproj" -- FAILED.

Done building project "TestingApp.csproj" -- FAILED.

Build FAILED.

I also tried to run it from terminal with dotnet run and it works, but I cannot use Visual Studio. Thanks.

RJFalconer
  • 10,890
  • 5
  • 51
  • 66
Isidore Ducasse
  • 401
  • 1
  • 4
  • 4

14 Answers14

42

Just remove BIN and OBJ directories from the project and rebuild.

John Bull
  • 933
  • 1
  • 12
  • 20
20

Try from command line:

  • dotnet clean
  • dotnet build

It worked for me. Take a look here for more info

Salim Chemes
  • 251
  • 1
  • 3
  • 2
    thanks for the answer. it didn't work unfortunately. the error persists in VS and I cannot build the project using VS. – Isidore Ducasse Mar 10 '19 at 23:42
  • I did this and got a lot of errors but did it several times then built the project from VS and it worked. I used the VS command line. – Missy Jan 30 '20 at 21:22
  • I think this worked for me, in that it made me realize that I had an instance of the app running, so stopped that one (and deleted the binaries all the same). So I'm not sure if that was in fact the issue, but it helped all the same. – Sipke Schoorstra Mar 07 '21 at 11:01
6

Root cause :-

This error due to Nuget packages version compatibility different in projects(Shared project,iOS Project,Android Projects).

Solution:-

1.Update the each Nuget packages where shows update version in front of nuget package.

2.Clean solution.

3.Build Solution,

Alok Kumar
  • 581
  • 1
  • 8
  • 13
3

In my case. Go to C:\Program Files(x86)\Microsoft Visual Studio\Shared then create a new folder name is "NugetPackages"

Build and run the program again, Problem is fixed.

  • I had this problem too, and this is my cause and solution. Although not related to OP's question, it still deserves an upvote. – ZP-ZPanda Sep 19 '22 at 13:33
0

Just had the same problem. Reason was, in Project Options of main-project Build-General the Target Framework was changed, don't know why. For my project it should be Xamarin.Mac Full Net 4.7.2, but for whatever reason it now was Xamarin.Mac Modern. Changed back to Full and everything was fine again.

I remember, it happened already again a while ago, after another update of VS Mac. As Xamarin user for many years in the meantime I know, that many Xamarin-Updates are breaking things, which were fine before.

Tom
  • 190
  • 3
  • 18
0

Try following steps on your project/lib :

  1. if you are working multiple directory structure then apply full rights on it
  2. if you are working with older version of NuGet then update them with latest or compatible version
  3. if still not working then delete bin folder and execute step 1 and 2 again.

it's worked for me.

Naimish Mungara
  • 213
  • 1
  • 4
  • 14
0

Open Visual Studio with elevated permission (Run As Administrator) Then try clean and rebuild.

Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92
0

I found (under VS2022 using .Net6) that all I had to do was create an empty folder under:

C:\Program Files (x86)\ComponentOne\Winforms Edition\bin\v5

and then perform a project rebuild via "Build/Rebuild" in the VS2022 menu.

Chris Raisin
  • 384
  • 3
  • 7
0

In my case running Visual Studio with elevated privilidges was the solution.

RHAD
  • 1,317
  • 3
  • 13
  • 37
0

In my case, I closed and re-opened VS 2022. Now its back working!

Robert Green MBA
  • 1,834
  • 1
  • 22
  • 45
0

I had this problem in a unit test project. The problem was a duplicate reference to a library, though it wasn't clear to start.

e.g.

UnitTest.csproj Project referenced:

  • Main.csproj
  • SharedLibraries.csproj

However, critically, Main.csproj also referenced SharedLibraries.csproj, so this error occurred.

Changing UnitTest.csproj to ONLY reference Main.csproj solved the problem (and still retained access to SharedLibraries.csproj via the main project).

JsAndDotNet
  • 16,260
  • 18
  • 100
  • 123
0

In my case, I added an existing project in my solution that I had before referenced as NuGet package in two projects in my solution. The problem was that in one of the solution projects, I referenced the external project as source code, while in the other solution project, I referenced it as NuGet package.

I guess that the same assembly with the same exported types caused a problem when importing it in two different ways.

The solution of the problem was to add the same assembly/project consistently in only one way in both solution projects, i.e. either as source code project or as NuGet package, but not mixed.

Oliver Konig
  • 1,035
  • 2
  • 14
  • 17
-1

For me, non of the solutions here worked, but a Visual Studio software update did the job.

It generally happens when the Mono's MSBuild - that is being used by Visual Studio to build the project - does not support the SDK version you're using, which can make many packages that are (e.g.) built for .NET 5 and requires Nuget 5 Packaging to fail to build with the MSBuild.

You would typically get one of the following errors:

  • Microsoft.NET.Sdk.targets(124, 5): [MSB4018] The "PACKAGE_NAME" task failed unexpectedly.
  • Microsoft.PackageDependencyResolution.targets(234, 5): [MSB4018] The "ResolvePackageAssets" task failed unexpectedly.

So installing or changing to the compatible MSBuild, or changing the SDK should usually fix the problem.

You can find more helpful information here:

Mayer Spitz
  • 2,577
  • 1
  • 20
  • 26
-2

Just rebuild the project. It automatically cleans and restores the required files then it build the project