Install multiple NuGet packages at once - visual-studio

Is it possible to use nuget to install multiple packages at once? That is, both download all nuget packages listed in packages.config and add the packages to the .csproj file.
What I do now is to use the NuGet Package Manager in Visual Studio and install each package one by one, but is there an easier way?
EDIT:
This question is not solved by How do I get NuGet to install/update all the packages in the packages.config? as it only downloads and installes the packages to the packages directory, and does not change the project files.
If I run
nuget install packages.config
It will install all packages in the packages.config file, but not update the project file.

Could you try to run this from the package manager console in Visual Studio:
Update-Package –reinstall
That should fix missing assembly references in your *.csproj files, if the packages are already in your packages.config.

Related

Nuget restore doesn't add reference to project

Nuget keeps on not doing what I expect:
Say I got a bunch of references in a packages.config and add that to a newly created project. Then nuget asks me to restore the packages, on answering yes, it only downloads the packages to the packages folder but forgets to add a reference the the project.
How to automatically also add a reference to my project once restored?
Lasse is correct about the NuGet restore. NuGet restore will only download the NuGet packages and extract them to the packages directory.
However with just the package information in the packages.config file there is a way to have NuGet add the references to the project.
First restore the NuGet packages.
Next open the NuGet Package Manager Console and reinstall the packages using:
Update-Package -reinstall
The above -reinstall command will uninstall and install the packages again and fix any missing references.
There are some limitations with the above command which are documented on the NuGet site.
Restoring packages will only download the packages and place them into the right folders on disk.
You get the references when you originally add the nuget packages to the project the correct way.
You should not add nuget packages to the projects by modifying the package configuration file, you should add them using the "Add Nuget reference" menu item on the References folder of the project.

How to update nuget packages without package manager of visual studio?

How to update nuget packages without package manager of visual studio, if the projects referenced in solution have different nuget package folders, then updating nuget packages from solution becomes tedious job. You need to update nuget packages per project. Is there a way to update nuget packages without using visual studio?
To update the nuget packages in solution, you can create a batch file with multiple commands or can execute command like mentioned below using command prompt:
Open command prompt and change the folder where Nuget.Exe is present.
NuGet.Exe Update [Solution File] -Id [Nuget package Id]
There are more switches to Nuget.Exe Update switch, like you can specify the nuget source. Make changes as required and you can successfully update nuget packages without opening the visual studio.

NuGet restore enabled but I still get an error

Why do I get the following build output error when I already have NuGet package restore enabled?
Restoring NuGet packages...
To prevent NuGet from downloading packages during build, open the
Visual Studio Options dialog, click on the Package Manager node and
uncheck 'Allow NuGet to download missing packages'.
All packages listed in packages.config are already installed.
MyProject.csproj: error : This project references NuGet package(s)
that are missing on this computer. Enable NuGet Package Restore to
download them.
It only happens on one project.
I am using Visual Studio 2013 and NuGet 2.8.
Make sure to upgrade to the latest version of NuGet which does package restore automatically. See this post by David Ebbo for more information: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
You're going to want to delete the NuGet targets (delete the .nuget folder and then manually edit your .csproj files and remove the lines that import the NuGet.targets file). This is no longer needed. When you compile your solution, NuGet will restore it.

How to fix deleted DLLs from NuGet's packages?

With NuGet, I added Json.NET (Newtonsoft.Json) to my code. As result of a mistake (adding code to CMS, ignoring DLLs, and checking out), my reference DLLs were deleted.
How do I restore ?
I followed all links in this SO question, but nothing brings back the DLLs.
If you still have the packages.config file you should be able to use nuget.exe to restore the packages in the packages folder. You can run nuget install followed by the path to your packages.config file.
nuget install packages.config
This will restore the packages to the packages folder but not modify your project.
If you do not have the packages.config file you could try running nuget install specifying the package id and the version instead.
If you have files in your packages folder you may want to remove those before running this command.

Reinstalling NuGet packages with NuGet installed as VS Extension

I would like to be able to install all of the NuGet packages in the packages.config, as per The NuGet docs. NuGet is installed as a VS Extension, and I can't seem to find nuget.exe. Is it possible to run:
nuget i packages.config -o Packages
Without maintaining a seperate copy of nuget.exe on a per project basis?
Reinstall all packages in all projects of the current solution:
Update-Package -Reinstall
You can find more information about reinstalling nuget packages here
Warning - using
Update-Package -Reinstall
or
Update-Package -Reinstall -IgnoreDependencies
may remove all of your packages and package.config files!
Always make sure that you have your backups performed first.
Scenario:
Solution with multiple projects
Each contains their own Nuget entries, some with the same packages (e.g., SharpRepository, Entity Framework)
Now copy folder without the packages folder for "distribution" somewhere else
Assume the packages folder wasn't included with the distribution
Now try the command Update-Package -Reinstall or if you have some alpha packages and/or are sure your dependencies are good, try Update-Package -Reinstall -IgnoreDependencies
Result:
Because the packages folder doesn't exist, the entries for your packages methodically go away, too. This can surprise some people - so be careful, is all I'm saying.
As an update to this post, NuGet 1.6 added support for the workflow to restore the packages at build time if missing.
Right-Click on the solution, click "Enable Package Restore Mode" to set it on.
More details at:
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
Found the solution on This blog entry. I needed to install NuGet.CommandLine, which makes nuget.exe. globally available in the VS command line. I can then set this up as a pre-build event to ensure that dependencies are downloaded.
A much easier option that you can keep enabled in Visual Studio during development to ease off your NuGet package installation related pain.
Keep both below mentioned options under NuGet Package Manager > General in checked state -
Allow NuGet to download missing packages
Automatically check for missing packages during build in Visual Studio
Have a look at the screenshot below:

Resources