Assets file project.assets.json not found. Run a NuGet package restore
Solution 1
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
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
In case when 'dotnet restore' not works, following steps may help:
- Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources
- Unchecked any third party package sources.
- Rebuild solution.
Solution 4
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
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.
NeverTrust
Updated on February 04, 2022Comments
-
NeverTrust over 2 years
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
-
Mark almost 6 yearsThis was also the fix for the build server. Added a Command Line step to run "dotnet restore" after normal NuGet restore.
-
Der_Meister almost 6 yearsYou may do it from MSBuild also: msbuild MySolution.sln /t:Restore
-
Michael almost 6 years@Der_Meister's solution to add the /t:Restore option worked for me, however, I had to build the solution twice (two separate build steps). First with the /t:Restore option and then again without it.
-
Der_Meister almost 6 years@Michael, try msbuild MySolution.sln /t:Restore;Build
-
Wai Yan Hein almost 6 yearsThis is the best, perfect and working solution. Thanks so much
-
Nordes over 5 yearsThis fix the issue with Appveyor, thanks. I don't understand why we need to do the restore manually. I tough that the build was automatically doing the restore :/
-
Ed Harrod over 5 yearsIf you have more than one solution file, you need to do
dotnet restore solutionfilename.sln
-
Gaspa79 over 5 yearsCan't believe this worked for me too after doing dotnet restore and only after this
-
Stark over 5 yearsI thought to myself that this could not possibly be it. After trying for another hour on other proposed solutions i finally tried this out of desperation and it solved my problem. Dammit man!
-
Lech Osiński over 5 yearsAlso can be achieved by adding step ".NET core" to pipeline (before build), and selecting "dotnet restore" command from dropdown. I'm talking specifically about VSTS pipeline here.
-
Anders Lindén over 5 yearsDo you have to run it many times? Do you need to combine it with normal nuget restore? Do you have to run it as administrator?
-
Sharbel about 5 yearsThis fixed the issue that I was having, thank-you so much!
-
zoidbeck about 5 yearsThis solution was the fix for me. Just don't forget to reopen VS afterwards.
-
CodeWarrior about 5 yearsThis answer should be at the beginning of the post not at the end. Solved my issue.
-
mpatel about 5 yearsYou saved my day! Thank you.
-
Tharindu Jayasinghe about 5 yearsI recently encountered this issue for Identity server Quickstart #1: Securing an API using Client Credentials and the above solution worked for me.
-
Johannes about 5 yearsThis issue happend for me when i worked on a Dockerfile. deleting those folders made the dotnet restore in the container work properly.
-
Sigex almost 5 yearsWow that was so annoying. Thanks for bothering to comment the issue here. Really appreciate it. - people still need to do dotnet restore on top
-
CPHPython almost 5 yearsThank you! I actually removed one source that was not relevant anymore (from another solution) and on the nuget.org and MSVS Offline Packages sources I clicked the Update button. After this
dotnet restore
worked. -
BitPusher16 almost 5 years@Der_Meister had a solution that almost worked for me in Azure Devops Build pipeline. /t:Restore fixed nuget issue but didn't build. Changed slightly to /t:Restore;Clean;Build and everything worked.
-
Water almost 5 yearsThis worked for me. Removed the space in the Local folder and it worked.
-
Neo over 4 yearsI had some separate connectivity issues on my work LAN that were inhibitive for NuGet. Rebooting my PC resolved the issue!
-
James Blackburn over 4 yearsThis worked for me. For those saying it doesnt work make sure you are opening the command window from the sln directory or better yet use the package manager console when the sln is open in VS
-
tdracz over 4 yearsThank you, that was it!
-
Starnuto di topo over 4 yearsI had to create a subfolder named "package", before issuing "dotnet restore", for it to work.
-
hosam hemaily over 4 yearsin my case i just renamed my physical folder by remove %20 and replace it with normal space and every thing is working well
-
NiallMitch14 over 4 yearsThe %20's in the folder name was the issue. Was so confused why it was failing. Thank you so much!
-
T.S. over 4 yearsThis is really not an answer because sometimes you use CLI tools to
get
andbuild
and you don't open VS. I know why it works with VS - because VS automatically resolves project dependencies. -
OutstandingBill over 4 years@T.S. the question is tagged with "Visual Studio 2017", so I'd say this is an answer. You raise an interesting point though, that the problem lies with VS resolving dependencies. If you have any more information on what's going wrong, I'm sure it would make interesting reading : )
-
OutstandingBill over 4 yearsI'm going to try this next time it happens. It could be a better approach than mine (close and reopen VS) which typically takes ages for me.
-
T.S. over 4 years+1. You caught me! With VS, oh well. His version 15.5 was buggy. I think 15.5/15.6 had host of issues for reference resolution. Now, here is the answer stackoverflow.com/a/58548856/1704458
-
Céryl Wiltink over 4 yearsAgree, this was the problem (and solution) for me too. Aditionally, creating a new .NET Core MVC project in a folder with '%20' also failed to properly create the project file itself (I had to manually include the created Model, View and Controller folders in the project for instance). That should have been my first clue project creation was not done properly.
-
StuartLC over 4 yearsYes - I found this when we started migrating old .Net Framework projects across to the new
.csproj
project format. -
meol over 4 yearsthanks! it was the space in the folder that messed it out for us.
-
oderibas about 4 yearsMicrosoft strongly recommends using
-t:build -restore
instead of/t:restore;build
See here: docs.microsoft.com/nuget/reference/… -
user7082181 almost 4 yearsit does not work at all, and how would it be a "perfect solution" since this kind of thing should be dealt by the ide itself...it's a brand new solution, it does not make any sens
-
hB0 almost 4 yearsIf you need 3rd party package sources or yours own organization over AzureDevOPs then follow this instruction: docs.microsoft.com/en-us/azure/devops/artifacts/nuget/…
-
lohithbb over 3 yearsThis was it - this seems to be an issue in TFS/Azure DevOps where spaeces are allowed.
-
Robert S. over 3 yearsIn my case there was an entry for Microsoft offline packages and it seemed to be invalid. Took ages to find that out. Thanks.
-
IEnjoyEatingVegetables over 3 yearsThis is cruel and unusual
-
Hemalatha M.R. over 3 yearsYes, I have added some custom NuGet references from the package manager, hence only not resolving that problem. Now works
-
Tyler over 3 yearsMight be a rare case, but I had to also remove a property from my .csproj... Remove this if it exists: <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>... now all is right in the world again.
-
Akos over 3 yearsCame to reply to this. If you are using AzureDevops Pipeline builds, you don't need a separate task for this, just add /t:Restore to MSBuild arguments on the solution build task.
-
humbads over 3 yearsIf you are running this from an ordinary command prompt (e.g. on a build server like CruiseControl.Net), make sure you are in the folder that contains your .csproj or other project files.
-
R13mus over 3 yearsFor me it does not work to do /t:Restore;Build but /t:Restore /t:Build, but thanks, your answer helped me !
-
computrius about 3 yearsStack overflow REALLY needs to allow multiple answers to be selected as accepted for a question. And the ability for people who didnt make the question to vote to override the original authors selected answer.
-
computrius about 3 yearsOr perhaps investigate WHY it isnt working instead of just blindly hacking away at your package sources... my guess is in your case you had one that was broken and it was causing YOUR restore to fail. In which case its not an issue with HAVING third party package sources; that would be ridiculous. Run dotnet restore from the nuget package manager as suggested above to see what is actually failing.
-
prisan about 3 years@computrius What's your solution then? Please share with everyone.
-
computrius about 3 years@prisan Looks like my comment hit close to home and you got offended and blinded to the fact that it IS the solution. Plus, you clearly didn’t read past the first sentence.
-
Arundale Ramanathan almost 3 years
dotnet restore
can be run in package manager console -
Noah almost 3 yearsI had the same problem in Jetbrains Rider IDE. I opened up the terminal in Rider and ran dotnet restore. It fixed the problem immediately
-
Eric almost 3 yearsThe rename of my local folder - replacing %20 with a space fixed it for me.
-
Sanushi Salgado over 2 yearsThanks! Running the command 'dotnet restore' fixed my project errors.
-
Ε Г И І И О over 2 yearsThis worked for me. Thank you!
-
Liam over 2 yearsThis has already been said
-
D Todorov over 2 yearsWorks as s charm !
-
jpt over 2 years
/t:Restore
turned out to be the fix to my problem in a heterogeneous solution (framework, core, and standard projects mixed). The standard/core projects were failing with the error until I used this approach. -
Irshad Faras over 2 yearsTried other solutions, this worked for me.
-
Muggin about 2 yearsYep. This is why I never add spaces in my own projects.
-
CervEd almost 2 yearsfriends don't let friends use spaces in names
-
Sebastian Castaldi almost 2 yearsWhen you work for big organizations, you don't get to choose the project name, usually is another team (most likely not developers) that chooses these names with spaces, by all means, if you have rights to create/modify the project name go for it, but like in my case you don't, then the above solution works