.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

It’s time to MVCify my website.

OK it’s time. I have been spending quite some time learning ASP.NET MVC. I’ve read the Professional ASP.NET MVC 1.0 book and watched numerous videos on the topic but until you sit down and create a real website with the technology, it just won’t click. To this end, I have decided to redo my website using MVC. Frankly it needed an overhaul anyway. I used a template to construct my home and resume pages and they used tables for layout. They work perfectly fine but are outdated and need to be replaced with the preferred CSS DIV tag layout.

So here we go my first crack at creating an MVC application. I’ll be refactoring the home page first and will follow with the resume, agenda, toolbox and jQuery sites. I’m not to sure about my blog as it uses BlogEngine.net. My silverlight gallery can certainly be ported to MVC but that will take a bit longer.

So far I have almost completed MVCifying my home page. Check it out here. Hover over the menu items, my photo and my name, all done with jQuery and CSS.

Once completed I will make available the source code for download.

Be the first to rate this post

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

Categories: ASP.NET MVC
Posted by CynotWhyNot on Thursday, July 23, 2009 3:56 PM
Permalink | Comments (142) | Post RSSRSS comment feed