# How to restore nuget packages when using MSBuild command line?

• ### Question

• I'm using Visual Studio 2015 Update 1 and nuget 3.3.0.167, and I want to use MSBuild command line to build my solution. but it does not automatically restore nuget packages. i'm not using TFS or VSO, i just want to use command line to make an old build script work correctly.

i found some blogs for this, but they all need a folder called .nuget. but i don't have such a folder when creating solution by VS 2015.

thanks

Thursday, January 28, 2016 2:21 AM

### All replies

• Hi Terry,

The "nuget.exe restore" command line allows you to easily restore all packages for a solution with a single command, by accepting a solution file or folder as an argument. The Restore command will open the solution file and find all projects within the solution. It will find the packages.config files for each of the projects and restore all of the packages found. It also restores solution-level packages found in the .nuget\packages.config file. Something like the following

nuget.exe restore path\to\solution.sln

I hope it helps.

Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Thursday, January 28, 2016 5:18 AM
• But i can't find the nuget.exe. I remember it should be in the .nuget folder under solution folder, but now (VS2015) there is no such folder anymore.

• Edited by Thursday, January 28, 2016 7:44 AM
Thursday, January 28, 2016 7:43 AM
• Hi Terry,

I think you should use Visual studio to download NuGet.exe, the tool will create a folder for your project. See http://docs.nuget.org/Consume/Package-Restore

Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Thursday, January 28, 2016 9:26 AM
• how to use VS to download NuGet.exe? i have already installed NuGet Package Manager for Visual Studio 2015 extension.

thanks

Friday, January 29, 2016 2:34 AM
• Hi Terry,

I copied the approach from the link I provided in my previous post.

MSBuild-Integrated Package Restore

Prior to NuGet 2.7, an MSBuild-Integrated Package Restore approach was used and promoted. While this approach is still available, the NuGet team suggests using the Automatic Package Restore and Command-Line Package Restore instead.

The MSBuild-Integrated approach requires user action to enable it for a solution. This is done from within the Visual Studio Solution Explorer by right-clicking on the solution and choosing 'Enable NuGet Package Restore'. On this gesture, the following actions occur:
2.NuGet saves these files, along with a NuGet.config file, into a .nuget folder at the root of the solution.
3.NuGet updates all projects in the soluton to have them import the .nuget\NuGet.targets file, extending MSBuild to invoke NuGet.exe's Install Command during build.

After that initial setup, building the solution through either Visual Studio or MSBuild from the command-line will restore packages during the build. NuGet.exe verifies package restore consent before downloading any missing packages, verifying only the 'Allow NuGet to download missing packages' setting.

The MSBuild-integrated approach to package restore has some drawbacks that vary in severity by situation.
1.Requires additional files within the solution folder.
2.Requires a targets file to be imported into all projects in the solution; this can introduce issues when projects are shared among multiple solutions.
3.Projects fail to load if the NuGet.targets file cannot be found.
4.Projects don't build successfully if any of the restored NuGet packages extend MSBuild through a targets/props file import.

For more information on the MSBuild-Integrated Package Restore approach, visit the Using NuGet without committing packages page.

To switch from MSBuild-Integrated Package Restore to Automatic Package Restore, see the walkthrough of migrating to Automatic Package Restore.


It also provides other package restore approach using VS or MSBuild, please have a look if the above is not appropriate for your scenario.

Regards,

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

Friday, January 29, 2016 4:49 AM
• but in my solution explorer's context menu, there is no 'Enable NuGet Package Restore' !!!

Friday, January 29, 2016 7:40 AM
• You can get a version of nuget.exe from https://dist.nuget.org/index.html

...or build one yourself since the code is here: https://github.com/NuGet/NuGet.Client

Filip Skakun

• Marked as answer by Sunday, February 14, 2016 2:25 AM
Wednesday, February 3, 2016 4:51 AM
• Do we need to add nuget.exe in the solution path and checkedin to TFS? Im facing same issue im looking to restore all my packages whiel im doing MSBuild. Appreciate your help on this. Im using VS2017 with Framework 4.6 standard(not core)
Friday, August 25, 2017 11:01 PM