Assets file project.assets.json not found. Run a NuGet package restore

NugetVisual Studio-2017.Net CoreNuget Package-Restore

Nuget Problem Overview


I'm trying to use nopCommerce(Which is written in .NET Core) but when I want to run the project I face 52 Errors telling me Run a nuget package restore

> Assets file ~\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. Nop.Web.MVC.Testsote

when I use the right click on the solution and selecting Restore Nuget Packages I get this message:
> All packages are already installed and there is nothing to restore.

but those 52 Errors are still there and in Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution there is nothing installed on the solution,also I Recently updated my VS2017 to 15.5.4

Nuget Solutions


Solution 1 - Nuget

To fix this error from Tools > NuGet Package Manager > Package Manager Console simply run:

dotnet restore

The error occurs because the dotnet cli does not create the all of the required files initially. Doing dotnet restore adds the required files.

Solution 2 - Nuget

In my case the error was the GIT repository. It had spaces in the name, making my project unable to restore

If this is your issue, just rename the GIT repository when you clone

git clone http://Your%20Project%20With%20Spaces newprojectname

Solution 3 - Nuget

In case when 'dotnet restore' not works, following steps may help:

  1. Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources
  2. Unchecked any third party package sources.
  3. Rebuild solution.

Solution 4 - Nuget

To those with the same issue as me in Azure DevOps / VSTS environment encountering a similar message:

> C:\Program Files\dotnet\sdk\2.2.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): Error NETSDK1004: Assets file '...\obj\project.assets.json' not found. Run a NuGet package restore to generate this file

Add /t:Restore to your MSBuild Arguments in Build Solution.

Solution 5 - Nuget

Closing and re-opening Visual Studio solved this issue for me, once I had made sure the NuGet packages had been restored as per other answers posted here.

Edit: Sometimes just trying to build again fixes the problem.

Solution 6 - Nuget

For me when i did - dotnet restore still error was occurring.

I went to
> 1 Tool -> NuGet Package Maneger -> Package Manager settings -> click on "Clear on Nuget Catche(s)" > > 2 dotnet restore

resolved issues.

Solution 7 - Nuget

In visual studio 2017 please do following steps:

  1. select Tool=>Options=>NuGet Package Manager=> Package Sources then uncheck Microsoft Visual Studio Offline Packages Option. enter image description here

  2. now open Tool=>NuGet Package Maneger=>Package Manager Console.

  3. execute command in PM>dotnet restore.

Hope its working...

Solution 8 - Nuget

If this error occurs as part of a build in Azure DevOps (TFS) and your build already has a NuGet restore task, this error may indicate the NuGet restore task was not able to restore all packages, especially if you use a custom package source (such as an internal NuGet server). Adding /t:Restore;Build to the MSBuild Arguments seems to be one way to resolve the error, but this asks MSBuild to perform an additional NuGet restore operation. I believe this succeeds because MSBuild uses the custom package source configured in Visual Studio. A preferable solution is to fix the NuGet restore task.

To configure a custom package source for the NuGet restore task:

  1. Create a NuGet.config file that lists all of the package sources (Microsoft Visual Studio Offline Packages, nuget.org, and your custom package source) and add it to source control.
  2. In the Nuget restore task under Feeds to use: select the option Feeds in my NuGet.config.
  3. Provide the path to NuGet.config.
  4. Remove the /t:Restore;Build option from the MSBuild task.

Additional information is available here.

Solution 9 - Nuget

For me I upgraded NuGet.exe from 3.4 to 4.9 because 3.4 doesn't understand how to restore packages for .NET Core.

For details please see https://stackoverflow.com/questions/45897271/dotnet-restore-vs-nuget-restore-with-teamcity

Solution 10 - Nuget

It was mentioned earlier but I just wanted to re-emphasize the importance of not have space anywhere in your pathing! This is what was getting me. You've been warned.

Solution 11 - Nuget

Select Tools > NuGet Package Manager > Package Manager Console

And then Run:

dotnet restore <project or solution name>

Solution 12 - Nuget

You will get required packages from "https://api.nuget.org/v3/index.json";. Add this in Package Resources. Also make sure other packages are unchecked for time being. And Click Restore Nuget Package on Solution Explorer enter image description here

Solution 13 - Nuget

Nothing above worked for me. But simply deleting all 'bin' and 'obj' folders did the trick.

Solution 14 - Nuget

Solved by adding /t:Restore;Build to MSBuild Arguments

Solution 15 - Nuget

little late to the answer but seems this will add value. Looking at the error - it seems to occur in CI/CD pipeline.

Just running "dotnet build" will be sufficient enough.

> dotnet build

dotnet build runs the "restore" by default.

Solution 16 - Nuget

I lost several hours on this error in Azure DevOps when I set the 'Visual Studio Build' task in a build pipeline to build an individual project in my solution, rather than the whole solution.

Doing that means that DevOps either doesn't build any (or possibly some, I'm not sure which) of the projects referenced by the project you've targeted for the build, and therefore those projects won't have their project.json.asset files generated, which then causes this issue.

The solution for me was to swap from using the VS Build task to the MSBuild task. Using the MSBuild task for an individual project correctly builds any projects referenced by the project you're building and eliminates this error.

Solution 17 - Nuget

This problem happening when your build tool is not set to do restore on projects set to use PackageReference vs packages.config and mostly affect Net Core and Netstandard new style projects.

When you open Visual Studio and build, it resolves this for you. But if you use automation, CLI tools, you see this issue.

Many solutions are offered here. But all you need to remember, you need to force restore. In some instances you use dotnet restore before build. If you build using MsBuild just add /t:Restore switch to your command.

Bottom line, you need to see why restoring can't be activated. Either bad nuget source or missing restore action, or outdated nuget.exe, or all of the above.

Solution 18 - Nuget

If simply restoring NuGet packages does not work make sure in Tools -> Options -> NuGet Package Manager -> General under Package Restore that the "Allow NuGet to download missing packages" is checked.

Then Restore NuGet Packages again OR just REBUILD after deleting obj and bin folders.

Solution 19 - Nuget

When using VSTS, check your global.json file. I had entered the sdk version as just "2.2" which caused a parse error (but not when building locally). Adding the full version, "2.2.104" solved the problem.

Solution 20 - Nuget

You can go for : Tools > NuGet Package Manager > Package Manager Console

And then Run:

dotnet restore

Solution 21 - Nuget

run your VS as administrator after that in package manager console run dotnet restore.

Solution 22 - Nuget

In my case, I had the following added to my *.csproj files to fully remove obj and bin folders on 'Clean'. Apparently, it was the culprit. Got rid of that and viola, all started to work again. Now I'm using the "Clean Bin" extension instead. Hope this might help anyone who is running into this issue, and none of the mentioned fixes works.

<Target Name="SuperClean" AfterTargets="Clean">
    <!-- Remove obj folder -->
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
    <!-- Remove bin folder -->
    <RemoveDir Directories="$(BaseOutputPath)" />
</Target>    

Solution 23 - Nuget

I have same problem and dotnet resotre not work for me. I Install this component:

enter image description here

and the run dotnet resotre and the problem has solved.

Solution 24 - Nuget

Another one, if by any chance you're using Dropbox, check for Conflicted in file names, do a search in your repo and delete all those conflicted files.

This may have happened if you have moved the files around.

Solution 25 - Nuget

Cause of this defect: you have to remove the injected Nuget in file explorer. Solution: Once you remove that Nuget in your system, then remove from following location. select Tool=>Options=>NuGet Package Manager=> Package Sources then uncheck Microsoft Visual Studio Offline Packages Option

Solution 26 - Nuget

This worked for me: added this package source: Microsoft and .net https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/ then run "dotnet restore" in the console

Solution 27 - Nuget

In my case I had a problem with the Available Package Sources. I had move the local nuget repository folder to a new path but I did not update it in the Nuget Available Package Sources. When I've correct the path issue, update it in the Available Package Sources and after that everything (nuget restor, etc) was working fine.

Solution 28 - Nuget

Very weird experience I have encountered!

I had cloned with GIT bash and GIT cmd-Line earlier, I encountered the above issues.

Later, I cloned with Tortoise-GIT and everything worked as expected.

May be this is a crazy answer, but trying with this once may save your time!

Solution 29 - Nuget

Seen this after adding a WinForms Core 3.1 project (from project templates) on VS-2019 vs 16.4.0 and trying to run it out of the box. Clean or Rebuild the entire solution did not work.

I just reloaded my solution.. that is File/Close Solution and then reopening it and rebuilding it solved the problem.

Solution 30 - Nuget

For me it turned out to be a nuget source credentials problem. I had recently changed my password for accessing a nexus server and visual studio was still using the old password when trying to access a nuget on that server through the windows credential manager. To fix it, I had to delete the entry for those outdated credentials in the credential manager and after, when I did a nuget restore, it prompted me for a password letting me enter the new password, which got saved in the credential manager again. You can access the credential manager from the cmd line using CmdKey.exe.

Solution 31 - Nuget

I received one message on Azure DevOps about don't find file

i need to create this on my YAML deployment file, AFTER BUILD TASK

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**\*.sln'
    feedsToUse: 'config'
    noCache: false

Solution 32 - Nuget

My issue was the build configuration platform was mismatched. Once, I changed "Any CPU" to "x64", I was able to publish.

enter image description here

Solution 33 - Nuget

What worked for me when I got this error was adding a global.json file but that may be related to using Paket instead of Nuget.

Solution 34 - Nuget

Had a similar issue. Turned out that I did not have access to %APPDATA%\Local\Temp\NuGetScratch\lock

Once I had access I could run nuget restore, but everything did start working.

Solution 35 - Nuget

I got the error when I created a lambda in dot net core in VS2017. What worked for me was to unload the project and load it back.

Solution 36 - Nuget

Try this (It worked for me):

  • Run VS as Administrator
  • Manual update NuGet to most recent version
  • Delete all bin and obj files in the project.
  • Restart VS
  • Recompile

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNeverTrustView Question on Stackoverflow
Solution 1 - NugetMostafa BouzariView Answer on Stackoverflow
Solution 2 - NugetSebastian CastaldiView Answer on Stackoverflow
Solution 3 - NugetprisanView Answer on Stackoverflow
Solution 4 - NugettaylorswiftfanView Answer on Stackoverflow
Solution 5 - NugetOutstandingBillView Answer on Stackoverflow
Solution 6 - NugetSpeedView Answer on Stackoverflow
Solution 7 - NugetManoj GuptaView Answer on Stackoverflow
Solution 8 - NugetJeremiah MercierView Answer on Stackoverflow
Solution 9 - Nugetuser8128167View Answer on Stackoverflow
Solution 10 - NugetMike HomolView Answer on Stackoverflow
Solution 11 - NugetAndre MesquitaView Answer on Stackoverflow
Solution 12 - NugetYogesh DangreView Answer on Stackoverflow
Solution 13 - Nugetalexbk66View Answer on Stackoverflow
Solution 14 - NugetAbdulsamet ILERIView Answer on Stackoverflow
Solution 15 - NugetSunny SharmaView Answer on Stackoverflow
Solution 16 - NugettomRedoxView Answer on Stackoverflow
Solution 17 - NugetT.S.View Answer on Stackoverflow
Solution 18 - NugetNexXView Answer on Stackoverflow
Solution 19 - NugetRob MinnisView Answer on Stackoverflow
Solution 20 - NugetsevenView Answer on Stackoverflow
Solution 21 - NugetLucas BritoView Answer on Stackoverflow
Solution 22 - NugetΕ Г И І И ОView Answer on Stackoverflow
Solution 23 - NugetArianView Answer on Stackoverflow
Solution 24 - NugetJose AView Answer on Stackoverflow
Solution 25 - Nugetbalaji sView Answer on Stackoverflow
Solution 26 - NugetHenry LView Answer on Stackoverflow
Solution 27 - Nugetuser11990436View Answer on Stackoverflow
Solution 28 - NugetBikramView Answer on Stackoverflow
Solution 29 - NugetGoodiesView Answer on Stackoverflow
Solution 30 - NugetJ. VolkyaView Answer on Stackoverflow
Solution 31 - NugetFelipe AugustoView Answer on Stackoverflow
Solution 32 - NugetLawManView Answer on Stackoverflow
Solution 33 - NugetSteveView Answer on Stackoverflow
Solution 34 - Nugetm_a_sView Answer on Stackoverflow
Solution 35 - NugetbomsView Answer on Stackoverflow
Solution 36 - NugetdalfonsopView Answer on Stackoverflow