NuGet Package Restore Not Working

后端 未结 20 1994
情书的邮戳
情书的邮戳 2020-12-02 04:06

I checked in a project on one computer, checked out on another, and find that the binaries installed by NuGet are missing. I could check them in to source control as well,

相关标签:
20条回答
  • 2020-12-02 04:45

    Note you can force package restore to execute by running the following commands in the nuget package manager console

    Update-Package -Reinstall

    Forces re-installation of everything in the solution.


    Update-Package -Reinstall -ProjectName myProj

    Forces re-installation of everything in the myProj project.

    Note: This is the nuclear option. When using this command you may not get the same versions of the packages you have installed and that could be lead to issues. This is less likely to occur at a project level as opposed to the solution level.

    You can use the -safe commandline parameter option to constrain upgrades to newer versions with the same Major and Minor version component. This option was added later and resolves some of the issues mentioned in the comments.

    Update-Package -Reinstall -Safe

    0 讨论(0)
  • 2020-12-02 04:47

    If none of the other answers work for you then try the following which was the only thing that worked for me:

    Find your .csproj file and edit it in a text editor.

    Find the <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> tag in your .csproj file and delete the whole block.

    Re-install all packages in the solution:

    Update-Package -reinstall
    

    After this your nuget packages should be restored, i think this might be a fringe case that only occurs when you move your project to a different location.

    0 讨论(0)
  • 2020-12-02 04:47

    For me, I had an empty tag NuGetPackageImportStamp in .csproj

    <NuGetPackageImportStamp>
        </NuGetPackageImportStamp>
    

    It should ideally contain some valid GUID.

    Removing this tag and then "Restore Nugets" worked for me.

    0 讨论(0)
  • 2020-12-02 04:51

    Automatic Package Restore will fail for any of the following reasons:

    1. You did not remove the NuGet.exe and NuGet.targets files from the solution's .nuget folder (which can be found in your solution root folder)
    2. You did not enable automatic package restore from the Tools >> Options >> Nuget Package Manager >> General settings.
    3. You forgot to manually remove references in all your projects to the Nuget.targets file
    4. You need to restart Visual Studio (make sure the process is killed from your task manager before starting up again).

    The following article outlines in more detail how to go about points 1-3: https://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

    0 讨论(0)
  • 2020-12-02 04:52

    There is a shortcut to make Nuget restore work.

    1. Make sure internet connection or Nuget urls are proper in VS Tools options menu

    2. Look at .nuget or nuget folder in the solution, else - copy from any to get nuget.exe

    3. DELETE packages folders, if exists

    4. Open the Package manager console execute this command

    • paste full path of nuget.exe RESTORE full path of .sln file!
    1. use Install-pacakge command, if build did not get through for any missing references.
    0 讨论(0)
  • 2020-12-02 04:53

    In VS2017, right-click on the solution => Open CommandLine => Developer Command Line.

    Once thats open, type in (and press enter after)

    dotnet restore
    

    That will restore any/all packages, and you get a nice console output of whats been done...

    0 讨论(0)
提交回复
热议问题