.NET Blog

Tony Cavaliere

 
My Favourite Albums
  And the Grappa wins.
E-mail me Send mail

Disclaimer

Hey unlike other bloggers I stand by what I say but just in case. The opinions expressed herein are my own except on Tuesday when the second card is not turned up otherwise it ain't worth squat.

© Copyright 2013

Creating a Complete Local NuGet Repository

I can’t say enough about it, NuGet is great!

NuGet is a .NET package management system integrated into VS2010. It is available as part of the ASP.NET MVC 3 download or separately from Codeplex. It’s free and open source and makes adding third party (or in house) libraries a snap.

Out of the box, the NuGet packages are retrieved from the internet, however, with very little configuration NuGet can retrieve packages locally or from a shared drive. Phil Haack as excellent post describing this configuration.

Steve Michelotti has an excellent post on how to use PowerShell to automatically pull down the NuGet packages from the internet an store them locally. The script is based on an early version of NuGet. Since then the location for the packages has changed, furthermore, the new feed will only list 100 packages at a time.

I have expanded on Steve’s PowerShell script allowing all the packages to be downloaded:

   1: $webClient = New-Object System.Net.WebClient
   2:  
   3:  $feed = [xml]$webClient.DownloadString("http://packages.nuget.org/v1/FeedService.svc/Packages()")   
   4:  $destinationDirectory = "C:\dev\nuget-lib"   
   5:  $records = $feed | select -ExpandProperty feed | select -ExpandProperty entry | select -ExpandProperty content                        
   6:  
   7:  while($records.Length -gt 0)
   8:  {
   9:      for ($i=0; $i -lt $records.Length; $i++) {   
  10:          $url = $records[$i].src   
  11:          $start = $url.IndexOf("/Download/") + 10
  12:          $packageAndVersion =  $url.Substring($start, $url.Length - $start)
  13:          $package = $packageAndVersion.Substring(0, $packageAndVersion.IndexOf("/"))
  14:          $start = $packageAndVersion.IndexOf("/") + 1
  15:          $len = $packageAndVersion.Length - $packageAndVersion.IndexOf("/") -1
  16:          $ver = $packageAndVersion.Substring($start, $len)
  17:          
  18:          $fileName = $url.Substring($startOfQuery, $url.Length - $startOfQuery)  
  19:          $fullPath = ($destinationDirectory + "\" + $fileName)  
  20:          write-host "Created package: $package.$ver.nupkg"
  21:          $webClient.DownloadFile($records[$i].src, ($destinationDirectory + "\" + $package + "." + $ver + ".nupkg"))  
  22:      }
  23:      $feed = [xml]$webClient.DownloadString("http://packages.nuget.org/v1/FeedService.svc/Packages()?`$skiptoken='$package','$ver'")
  24:      $records = $feed | select -ExpandProperty feed | select -ExpandProperty entry | select -ExpandProperty content
  25:  }

 

The trick is to continue querying the feed until all the packages are downloaded. The feed will only list 100 packages at a time. I could not find any way to override this behaviour. Fortunately, the feed contains the URL to fetch the next set of packages (Fiddler to the rescue). This is done on line 23 of the Powershell script, which adds the $skiptoken to the end of the URL.

The script will deposit all the NuGet packages to a local directory c:\dev\nuget-lib (line 4). Go ahead and change the location to meet your needs.

At the time of writing this post the feed had a total of 393 packages. That ‘s right 393 packages!

Currently rated 1.4 by 112 people

  • Currently 1.446429/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: .NET | ASP.NET MVC | VS2010
Posted by CynotWhyNot on Saturday, January 15, 2011 6:34 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Increasing Productivity: Add Reflector as an External Tool

You have just built an assembly in Visual Studio and want to look at it using a tool like Lutz Roeder's Reflector. So what do you do? You start reflector, go to the  File->Open menu option and navigate to the directory containing the assembly. Sound familiar? Wouldn't it be great if it was possible to start reflector from within the IDE and automatically load the assembly? Well you can using the External Tools feature from within Visual Studio.

Here are the steps:

1. Navigate to the Tools menu and select External Tools. The External Tools dialog will appear.

VSIDE Exteranl Tools Dialog

2. Enter a title (the character after ampersand will become the ALT key), command (location of reflector executable) and arguments ($(ItemPath) is the file currently selected in the solution explorer). In the above, I setup the title to be &Reflector which means the hot key will be Alt R.

That's it you are done. Now whenever you want to reflect, select the assembly in the solution explorer, select Tools menu item, and then select the newly created menu item for reflector. Alternatively you can use the hotkey Alt T + Alt R (assuming you setup the hot key as per step 2).

Happy Reflecting!

Guess the Movie

There are two kinds of spurs, my friend. Those that come in by the door,  those that come in by the window.

Currently rated 1.4 by 63 people

  • Currently 1.428573/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: .NET
Posted by CynotWhyNot on Tuesday, March 18, 2008 2:00 PM
Permalink | Comments (10) | Post RSSRSS comment feed