VisualStudio 2013 list all NuGet packages - asp.net-mvc

I have a mvc 5 web project with a number of NuGet packages installed (like email, log, pagedlist etc).
In a new similar project I would like to install the same NuGet packages. How can I in the old project list all installed NuGet packages?

You can find a packages.config file in the old project's root directory.
You can copy it to the new project.
If you go to Tools -> NuGet Packet Manager -> Packet manager settings and check Allow NuGet to download missing packages and the other check box that states Automatically check for missing packages during build in Visual Studio it will download it for you next time you build.

If you want to list all installed nuget packages for the project take a look at this one.
http://blogs.msdn.com/b/david_kidder/archive/2014/08/19/micro-blog-how-to-list-installed-nuget-packages-from-package-manager-console-and-be-able-to-read-them.aspx
You might also want to enable nuget package restore to restore the packages when rebuilding your project/s.
Here's another link for you - http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

In the root folder of your original project find a packages.config file. Copy its contents to your new project, same file name.
Go to Visual Studio > Tools > Package Manager Settings > General
Enable "Allow Nuget to download..." and "Automatically check for missing..."
Now build your new project

Most of the answers here are partially correct.
The first part is true. The packages.config file lists all packages that are used by the project.
However, all the answers about using Package Restore are incorrect. Package Restore will download any missing packages, however it is NOT the same as installing a package into a project. It will not add references, run any install.ps1 scripts, or add files, modify .config, etc. Package Restore simply downloads missing packages. It is assumed that the packages were already installed to the project.
In order for the packages to be correctly installed in your new project, open the Package Manager console, then type:
Update-Package -ProjectName MyProjectName -Reinstall
This will force NuGet to run through the install process and correctly install the package into your project.

Related

Update Packages of a MVC Project

Im trying to use an ASP.NET web application downloaded from the internet. Im looking for a way restore all the dependencies/packages in a quick way (clean and building the project did not solve it), rather than installing them via nuget one by one. Is there anyway to download and install/resolve (version issues) all the necessary packages at once?
I tried below package manager console commands, but they did not resolve the package conflicts.
Update-Package -Reinstall,
nuget install packages.config and other solutions here - How do I get NuGet to install/update all the packages in the packages.config?
[resolve/install packages]
Can someone help? Maybe Im using wrong commands or doing something wrong.
If you go into Tools > Nuget Package Manager > Manage Nuget Packages for Solution, it will show a yellow bar at the top asking you if you want to restore missing packages. That's a manual way, but there are also some important VS options you want to look at as well, one being an option to restore packages on build.
There is a generic restore option as well from the package manager console, and that should have worked if it was simply a matter of reimporting the missing packages...
Update-Package -reinstall
You can try to delete the folders, than reinstall using these options. However, is there a possibility there is a .NET framework version mismatch with the version of the DLL's? Maybe some of the DLL's need updated?
Remove package folders from Package folder - don't remove package.config. Next, build you application - nuget should automatically restore all packages.

This project references NuGet Packages that are missing:

I've just imported the .sln of the source files of an open source software, and I'm running into many built error like this:
"This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them."
Right Click this Project> "Manage NuGet Packages" > "Settings":
under "NuGet Package Manager" drop-down
I do have both options under "Package Restore" checked.
How do I enable "NuGet Package Restore" on .csprojs?
You can right-click on your solution, and choose Manage NuGet Packages for Solution....
When there are packages used that are not downloaded, you will get a yellow bar with the option to restore packages on top of the Manage NuGet Packages screen.
See this page for more documentation.
You can open the Manage NuGet Packages for Solution dialog for a project as well.
You can automate the downloading of packages on build as well, by right-clicking the solution, and choosing Enable NuGet Package Restore.
In my case this issue resolved when I updated some packages for which update is available. It might not downloaded those package due to its available update. Updating those packages and clean-build solution worked for me.

NuGet adds Packages folder to the solution. Should it be part of Source control?

I am using NuGet to add packages to my solution. NuGet added a Packages folder to my visual studio’s solution root folder. The concerning part is that the “packages” folder is not part of source control. That means the source code comes from TFS, but the project references come from a folder that is fed by external source. People can put malicious code in the packages folder and build the application.
I like to understand how my other colleagues that get the source code from the TFS source control can build the project with packages folder not being part of the source control?
We did have a similar problem where our build server wasn't allowed to have internet connection, so couldn't download packages. We started with creating our own NuGet Source, which was simply a shared folder with all packages copied to it. The visual studio projects would of course use these packages rather than packages hosted on www.nuget.org
I must say that we scrapped this idea because of the overhead of doing it as our package usage increased.
My advise is that if you are worried about packages downloaded at build time, store the packages folder on source control.
NuGet supports automatic package restoration so your colleagues who use this feature will automatically download required packages. There is a policy at nuget.org that prevents user to delete or update exact version of package once it is published so it can support package restore without any interruptions - see this answer for more detail. If you are using other package sources than nuget.org than you should check their package deletion/update policy because it may be different.

MVC Nuget Installing Multiple Packages

I'm building a new solution/project. I copied all the files over and moved all the packages over to the packages folder. When I reference them via nuget, it says they are installed, but
they are not. If they were, I would see them in the installed tab.
First why does it say installed, next how can I install multiple packages at once, instead of
doing it individually. I have like 10+ packages I need to install. This is pain in
the ass, if I have to install each individually. We should be able to run a command that
checks to see if all the packages in the package folder have been installed, if not, install them. Is there a command for this?
Use nuget.exe for this. see following question and google search
nuget install packages.config
Or with NuGet 2.7 you can restore allpackages in the solution using the command line.
nuget restore YourSolution.sln

Referenced Dll's not found in Team Foundation Service (or: nuget packages not available on other pc)

when I create a build for the Team Foundation Service, I get all kind of reference dll's not found exceptions.
These references are added by nugget packages.
I've added the 'package restore' option on the solution which added 3 files in a .NuGet folder.
EDIT
When i got the solution from TFS on another pc, i got the same errors (missing dll's), so it's not only the TFS build service having problems.
The missing dll's are are missing files from installed nuget packages (some are part of the default VS template, Unity was a package i added later), which (the packages) are added on the first pc, but then are missing on the next pc (that's why i added the 'or' in the title of this question)
How can i get the Nuget added files on pc2 too?
I guess you've found a solution by now. I write this just to provide an answer for this question.
To have NuGet packages automatically downloaded on another PC, you need to enable NuGet package restore on build. You do this in two steps:
Right click the solution and select Enable NuGet Package Restore.
This will add a .nuget solution folder with NuGet.Config, NuGet.exe and NuGet.targets underneath it. These files should actually be checked in to source control, but the binary file is tiny. It will also modify the MSBuild scripts in all projects of the solution to import the NuGet.targets file to hook NuGet into the build process.
In Tools -> Library Package Manager -> Package Manager Settings make sure the option 'Allow NuGet to download missing packages during build' is checked.
This step must be done on all machines.
Now the BuildDependsOn property of all project build scripts should make the RestorePackages target in NuGet.targets kick in and download missing packages before you get build errors for missing references.

Resources