问题
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
回答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.
回答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
回答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.
回答4:
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.
回答5:
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.
回答6:
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.
回答7:
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.
2) now open Tool=>NuGet Package Maneger=>Package Manager Console. 3) execute command in PM>dotnet restore.
Hope its working...
回答8:
Select Tools > NuGet Package Manager > Package Manager Console
And then Run:
dotnet restore <project or solution name>
回答9:
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 dotnet restore vs. nuget restore with teamcity
回答10:
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.
回答11:
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.
回答12:
Nothing above worked for me. But simply deleting all 'bin' and 'obj' folders did the trick.
回答13:
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.
回答14:
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.
回答15:
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.
回答16:
run your VS as administrator after that in package manager console run dotnet restore.
回答17:
If @mostafa-bouzari suggestion doesn't help, check carefully in 'Error list' or 'Output' windows for errors why NuGet cannot restore, e.g. because of net problem if you're behind proxy.
回答18:
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.
回答19:
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
回答20:
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
回答21:
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.
回答22:
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.
回答23:
Solved by adding /t:Restore;Build to MSBuild Arguments
来源:https://stackoverflow.com/questions/48440223/assets-file-project-assets-json-not-found-run-a-nuget-package-restore