Coder Perfect

How do I enable NuGet Package Restore in Visual Studio?

Problem

There’s a similar post on Stack Overflow, but it doesn’t assist with my problem, which could be due to the fact that I’m using Visual Studio 2015.

How can I get VS2015 to show the “Enable NuGet Package Restore” option?

I started an empty ASP.NET Web Application by going to File > New Project. This menu option is what I’m looking for.

I should remark that I searched my project folder for any pre-existing nuGet files and found none.

Asked by Dan Beaulieu

Solution #1

I finally found this document on Migrating MSBuild-Integrated solutions to Automatic Package Restore after a long search, and I was able to overcome the issue using the methods given there.

When editing your files by hand, here’s what you’ll be looking for:

Solution File (.sln)

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F4AEBB8B-A367-424E-8B14-F611C9667A85}"
ProjectSection(SolutionItems) = preProject
    .nuget\NuGet.Config = .nuget\NuGet.Config
    .nuget\NuGet.exe = .nuget\NuGet.exe
    .nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject

(.csproj /.vbproj) Project File

  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

Answered by Vinney Kelly

Solution #2

In VS2015, Microsoft no longer supports the ‘Enable NuGet Package Restore’ option, so you’ll have to make some manual adjustments to migrate old solutions or add the capability to new ones. NuGet Package Restore has a good description of the new capability.

There is also (as previously noted) a migration guide for existing projects here: Migration Guide for NuGet

When upgrading:

When starting a new project, keep the following in mind:

This configuration file will allow you to centralize all of your packages in one location, eliminating the need for 20 distinct copies of the same package to float throughout your file system. The relative path will vary based on the structure of your solution directory, but it should refer to a directory that is shared by all of your solutions.

After completing step 5, you must restart Visual Studio. Nuget won’t notice the modifications unless you tell it to.

Finally, you may need to uninstall and then reinstall the packages using the ‘Nuget Package Manager for Solutions.’ I’m not sure if this was a result of the Powershell script I executed or simply a way to reactivate NuGet. When I checked projects out of TFVC after completing all of these processes, my intricate build architecture worked wonderfully in bringing down new packages.

Answered by Quarkly

Solution #3

In VS2015, there is no option to ‘Enable NuGet Package Restore,’ as Mike has mentioned. You’ll have to manually start the restoration procedure. Using the NuGet Package Management Console is a convenient way to do this without having to deal with files and directories: Enter console, open the management console, and type command: into the ‘Quick start’ area (typically in the upper right corner).

Update-Package –reinstall

This will reinstall all of the projects’ packages in your solution. Enter the following to designate a single project:

Update-Package –reinstall -ProjectName MyProject

Of course, this is only essential when the Restore button – which VS2015 occasionally provides – is unavailable. Here are some more useful update commands that are mentioned and explained: https://docs.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages

Answered by Jack Miller

Solution #4

Optionally you can remove all folders from “packages” folder and select “Manage NuGet Packages for Solution…”. In this case “Restore” button appears on NuGet Packages Windows.

Answered by Ivan Branets

Solution #5

If you run into any issues or are missing any packages, simply right-click on your project and choose “Manage NuGet Packages for Solution…” After clicking this, a screen will appear with a menu bar that says “Restore”:

When you click on it, the necessary items will be downloaded and installed immediately. This, I believe, is what you’re seeking for; it fixed my issues.

Answered by Yenthe

Post is based on https://stackoverflow.com/questions/27895504/how-do-i-enable-nuget-package-restore-in-visual-studio