添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Have you provided consent to NuGet to restore? Go to tools, options, search for NuGet, and the check the "Allow NuGet..." option. imps Jan 26, 2018 at 0:54 If anyone is on a Mac, we had this problem and fixed it by removing spaces in the repository path (which was created during the git pull): My%20Project becomes MyProject. David Hague Jun 3, 2020 at 16:08 May take a look here at MS Docs with various workarounds (updated May 2018): learn.microsoft.com/en-us/nuget/consume-packages/… With nuget things never run smooth as click and go! hB0 Jun 30, 2020 at 16:31 @DavidHague thank you for the tip on fixing the repo path with spaces on a Mac - that was my problem - thanks! AVH Sep 14, 2020 at 2:40

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.

This was also the fix for the build server. Added a Command Line step to run "dotnet restore" after normal NuGet restore. – Mark Jun 8, 2018 at 9:18 @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. – Michael Jul 19, 2018 at 16:43 If you have more than one solution file, you need to do dotnet restore solutionfilename.sln – Ed Harrod Sep 13, 2018 at 8:28

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
                in my case i just renamed my physical folder by remove %20 and replace it with normal space and every thing is working well
– hosam hemaily
                Sep 25, 2019 at 8:29
                The %20's in the folder name was the issue. Was so confused why it was failing. Thank you so much!
– NiallMitch14
                Oct 15, 2019 at 10:27
                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.
– Céryl Wiltink
                Dec 29, 2019 at 9:44
  • Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources
  • Unchecked any third party package sources.
  • Rebuild solution.
  • I recently encountered this issue for Identity server Quickstart #1: Securing an API using Client Credentials and the above solution worked for me. – Tharindu Jayasinghe May 4, 2019 at 12:19 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. – CPHPython Jul 10, 2019 at 10:33 If you need 3rd party package sources or yours own organization over AzureDevOPs then follow this instruction: learn.microsoft.com/en-us/azure/devops/artifacts/nuget/… – hB0 Jun 30, 2020 at 16:02 In my case there was an entry for Microsoft offline packages and it seemed to be invalid. Took ages to find that out. Thanks. – Robert S. Oct 29, 2020 at 10:39 Yes, I have added some custom NuGet references from the package manager, hence only not resolving that problem. Now works – Hemalatha M.R. Nov 20, 2020 at 7:25

    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.

    In Azure DevOps build pipeline, add /t:Restore here:

    Might 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. – Tyler Dec 31, 2020 at 20:20 Just wanted to acknowledge that this still works today in off-prem ADO with Git. I spent hours troubleshooting a pipeline for a VS 2022 .Net 7 build. This solved my issue - so thank you from one Swiftie to another (I have a 14YO daughter so it's required apparently). – Donny McCoy Dec 20, 2022 at 2:11 This appeared to fix my pipeline, but then I was getting an empty artifact. It ended up being that an SSRS project was recently added to the solution, but the build server didn't have SSRS support yet. – Design.Garden Apr 22 at 23:40 This fixed the issue for me, thanks. I've added an image to the solution to make it really clear where to add the build arg. – robnick Jul 16 at 4:23

    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.

    I had some separate connectivity issues on my work LAN that were inhibitive for NuGet. Rebooting my PC resolved the issue! – Neo Aug 19, 2019 at 8:23 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. – T.S. Oct 24, 2019 at 19:48 @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 Oct 25, 2019 at 0:48 +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 – T.S. Oct 25, 2019 at 1:17

    I went to

    1 Tool -> NuGet Package Maneger -> Package Manager settings -> click on "Clear all NuGet Cache(s)"

    2 dotnet restore

    resolved issues.

    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. – OutstandingBill Oct 25, 2019 at 0:52

    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...

    this is what helped me - I had spaced in my path to my projects and after I removed them, it fixed it! – Mark Jul 22, 2022 at 0:21

    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:

  • 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.
  • In the Nuget restore task under Feeds to use: select the option Feeds in my NuGet.config.
  • Provide the path to NuGet.config.
  • Remove the /t:Restore;Build option from the MSBuild task.
  • Additional information is available here.

    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

    Yes - I found this when we started migrating old .Net Framework projects across to the new .csproj project format. – StuartLC Jan 6, 2020 at 17:28 To update nuget.exe... run from a VS command prompt: nuget.exe update -self It was only AFTER updating to the latest nuget, and then doing dotnet Restore that these errors went away for me – James S Aug 11 at 15:35 For me it does not work to do /t:Restore;Build but /t:Restore /t:Build, but thanks, your answer helped me ! – R13mus Feb 12, 2021 at 9:00 This issue happend for me when i worked on a Dockerfile. deleting those folders made the dotnet restore in the container work properly. – Johannes May 16, 2019 at 15:15

    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.

    /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. – jpt Dec 29, 2021 at 13:38

    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.

    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. – Lech Osiński Dec 11, 2018 at 13:57

    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.

    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.

    I did not have any NuGet in my CLI/C++. VS2022 built fine. However, MSBuild did not work giving me error NETSDK1004: Assets file ... obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

    The solution to my issue was removing the following from the vcxproj file.

    <EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
    

    I suppose changing true to false might work. I removed the line and MSBuild now works.

    Changing to false did not work for me, but removing the whole line did! Thanks for the solution – Bruce Ikin Mar 7 at 23:14

    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>    
    

    To fixed this issue. First you have to close the Visual Studio, then restart again in administrative mode.

    Create an new project or run your older project. Then Go

    Tools > NuGetPackage Package Manager > Package Manager Console
    

    An console will be open in below

    Then put a command

    dotnet restore 
    

    It will fixed all your problem.

    Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation? – Jeremy Caney Jul 27 at 0:19

    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.

    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

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

    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.

    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!