Click here to Skip to main content
12,458,167 members (58,279 online)
Click here to Skip to main content
Add your own
alternative version

Stats

8.7K views
2 bookmarked
Posted

NuGet: How to Install a Package in 19 Easy Steps

, 8 Jun 2013 Apache
Rate this:
Please Sign up or sign in to vote.
How to install a NuGet package in 19 easy steps

Introduction

If they tell you the machines will outsmart us very soon, don’t believe it. Here’s why.

Tonight I was trying to add “Unity” dependency injection framework to my .NET 4 project under Visual Studio 2010 via NuGet. Yes, I know, stone axes are no longer supported, but whatever.

Here are the list of steps, just for my record, and perhaps for someone’s sadistic geeky amusement, if they are into that kind of stuff. So,

  1. Opened Tools->Library Package Manager->Manage NuGet Packages for Solution. Typed “Unity” in the search box. It came out first.
  2. Clicked on “Install”. Was told that this version of Unity requires .NET 4.5 which none of my projects supports (duh!).
  3. Searched for a button or menu to list older versions – did not find any.
  4. Googled how to install older version with NuGet – did not find any encouraging results. But found NuGet PowerShell reference instead.
  5. Did Get-Package -ListAvailable -Filter Unity in Powershell. Got 40 results, in alphabetical order, none of them is Unity. Tried -First and -Skip options: no can do, a subset of the same 40 results.
  6. Googled it. Found something about a bug in NuGet that is fixed in the new version.
  7. Went to update NuGet to version 2.5 via Visual Studio Extension Manager. Installation failed, complaining something about the signature of my current NuGet not matching what they expect. Well, it did not complain per se, it just stated the failure, and gave the link to an installation log. The message with the actual root cause was in the middle of a very long line towards the end of file, around column 200, so some serious horizontal scrolling was required.
  8. Went to uninstall current NuGet in the Extension Manager. Install button is disabled.
  9. Googled it. Re-ran Visual Studio as administrator. Uninstalled current Nu-Get.
  10. Installed NuGet 2.5. First small victory!
  11. Did Get-Package -ListAvailable -Filter Unity in Powershell. It returned over a hundred packages, Unity came 96th. But this displays only the latest version, and I wanted the previous one.
  12. Tried to find the way to limit the search, so it would return just Unity. No cigar. According to the documentation -Filter searches in “package Id, the description and tags”. Trying to specify “The Unity Application Block” as a filter does not do any good: even more packages are returned. But -Skip 96 - First 1 gives me only Unity. OK so far.
  13. Trying Get-Package -ListAvailable -Filter Unity -AllVersions -Skip 96 -First 1. It waits a while (10 seconds or so), and then gives me Cavity.ServiceLocation.Unit... 1.1.0.787. Well, apparently it skips lines, not packages. Argh.
  14. Googled it. No cigar. Found a reference to another command line, the nuget.exe tool.
  15. Downloaded nuget.exe. It refused to run, requesting that I set some environment variable. Well, I did. It ran.
  16. Did nuget list unity. Get a hundred packages again.
  17. Did nuget list Unity -allversions and redirected output to a file. It took several minutes to create the file, and it came out with 1525 lines of text.
  18. Found that the previous version of Unity is (ta-da) 2.1.505.2. It’s right there, in front of your eyes, proudly sitting on line 1353.
  19. Back to Powershell, Install-Package Unity -Version 2.1.505.2.

Victory at last!

Some points to raise with the NuGet team(s):

  • A search by Package Id only would be nice; an exact search by Id would be even nicer
  • Why is it that when I search for Unity in Gallery it comes up first, and not 96th? Do they have a different API? If yes, why isn’t it available via Powershell or command line?
  • Installing previous version of a package should not require a degree in forensic science; having a menu listing all versions would save me 1.5 hours of work and lots of nerve cells.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Share

About the Author

Ivan Krivyakov
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site: www.ikriv.com.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionMakes Me Feel a Bit Better Pin
MikeS16-Jan-14 5:14
memberMikeS16-Jan-14 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 8 Jun 2013
Article Copyright 2013 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid