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

260,688

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:

  1. Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources
  2. Unchecked any third party package sources.
  3. 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.

Share:
260,688
NeverTrust
Author by

NeverTrust

Updated on February 04, 2022

Comments

  • NeverTrust
    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
    Mark almost 6 years
    This was also the fix for the build server. Added a Command Line step to run "dotnet restore" after normal NuGet restore.
  • Der_Meister
    Der_Meister almost 6 years
    You may do it from MSBuild also: msbuild MySolution.sln /t:Restore
  • Michael
    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
    Der_Meister almost 6 years
    @Michael, try msbuild MySolution.sln /t:Restore;Build
  • Wai Yan Hein
    Wai Yan Hein almost 6 years
    This is the best, perfect and working solution. Thanks so much
  • Nordes
    Nordes over 5 years
    This 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
    Ed Harrod over 5 years
    If you have more than one solution file, you need to do dotnet restore solutionfilename.sln
  • Gaspa79
    Gaspa79 over 5 years
    Can't believe this worked for me too after doing dotnet restore and only after this
  • Stark
    Stark over 5 years
    I 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
    Lech Osiński over 5 years
    Also 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
    Anders Lindén over 5 years
    Do 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
    Sharbel about 5 years
    This fixed the issue that I was having, thank-you so much!
  • zoidbeck
    zoidbeck about 5 years
    This solution was the fix for me. Just don't forget to reopen VS afterwards.
  • CodeWarrior
    CodeWarrior about 5 years
    This answer should be at the beginning of the post not at the end. Solved my issue.
  • mpatel
    mpatel about 5 years
    You saved my day! Thank you.
  • Tharindu Jayasinghe
    Tharindu Jayasinghe about 5 years
    I recently encountered this issue for Identity server Quickstart #1: Securing an API using Client Credentials and the above solution worked for me.
  • Johannes
    Johannes about 5 years
    This issue happend for me when i worked on a Dockerfile. deleting those folders made the dotnet restore in the container work properly.
  • Sigex
    Sigex almost 5 years
    Wow 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
    CPHPython almost 5 years
    Thank 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
    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
    Water almost 5 years
    This worked for me. Removed the space in the Local folder and it worked.
  • Neo
    Neo over 4 years
    I had some separate connectivity issues on my work LAN that were inhibitive for NuGet. Rebooting my PC resolved the issue!
  • James Blackburn
    James Blackburn over 4 years
    This 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
    tdracz over 4 years
    Thank you, that was it!
  • Starnuto di topo
    Starnuto di topo over 4 years
    I had to create a subfolder named "package", before issuing "dotnet restore", for it to work.
  • hosam hemaily
    hosam hemaily over 4 years
    in my case i just renamed my physical folder by remove %20 and replace it with normal space and every thing is working well
  • NiallMitch14
    NiallMitch14 over 4 years
    The %20's in the folder name was the issue. Was so confused why it was failing. Thank you so much!
  • T.S.
    T.S. over 4 years
    This is really not an answer because sometimes you use CLI tools to get and build and you don't open VS. I know why it works with VS - because VS automatically resolves project dependencies.
  • OutstandingBill
    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
    OutstandingBill over 4 years
    I'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.
    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
    Céryl Wiltink over 4 years
    Agree, 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
    StuartLC over 4 years
    Yes - I found this when we started migrating old .Net Framework projects across to the new .csproj project format.
  • meol
    meol over 4 years
    thanks! it was the space in the folder that messed it out for us.
  • oderibas
    oderibas about 4 years
    Microsoft strongly recommends using -t:build -restore instead of /t:restore;build See here: docs.microsoft.com/nuget/reference/…
  • user7082181
    user7082181 almost 4 years
    it 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
    hB0 almost 4 years
    If 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
    lohithbb over 3 years
    This was it - this seems to be an issue in TFS/Azure DevOps where spaeces are allowed.
  • Robert S.
    Robert S. over 3 years
    In my case there was an entry for Microsoft offline packages and it seemed to be invalid. Took ages to find that out. Thanks.
  • IEnjoyEatingVegetables
    IEnjoyEatingVegetables over 3 years
    This is cruel and unusual
  • Hemalatha M.R.
    Hemalatha M.R. over 3 years
    Yes, I have added some custom NuGet references from the package manager, hence only not resolving that problem. Now works
  • Tyler
    Tyler over 3 years
    Might be a rare case, but I had to also remove a property from my .csproj... Remove this if it exists: <RestorePackagesWithLockFile>true</RestorePackagesWithLockFi‌​le>... now all is right in the world again.
  • Akos
    Akos over 3 years
    Came 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
    humbads over 3 years
    If 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
    R13mus over 3 years
    For me it does not work to do /t:Restore;Build but /t:Restore /t:Build, but thanks, your answer helped me !
  • computrius
    computrius about 3 years
    Stack 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
    computrius about 3 years
    Or 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
    prisan about 3 years
    @computrius What's your solution then? Please share with everyone.
  • computrius
    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
    Arundale Ramanathan almost 3 years
    dotnet restore can be run in package manager console
  • Noah
    Noah almost 3 years
    I 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
    Eric almost 3 years
    The rename of my local folder - replacing %20 with a space fixed it for me.
  • Sanushi Salgado
    Sanushi Salgado over 2 years
    Thanks! Running the command 'dotnet restore' fixed my project errors.
  • Ε Г И І И О
    Ε Г И І И О over 2 years
    This worked for me. Thank you!
  • Liam
    Liam over 2 years
  • D Todorov
    D Todorov over 2 years
    Works as s charm !
  • jpt
    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
    Irshad Faras over 2 years
    Tried other solutions, this worked for me.
  • Muggin
    Muggin about 2 years
    Yep. This is why I never add spaces in my own projects.
  • CervEd
    CervEd almost 2 years
    friends don't let friends use spaces in names
  • Sebastian Castaldi
    Sebastian Castaldi almost 2 years
    When 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