Download all nuget packages to your local server using powershell

by Damiaan Peeters 21. January 2013 09:02

Some time ago I found this script to download the nuget Packages to you local server.  Just for a reference I’ll put it the blog. They way I run this is using the Windows Powershell ISE.


I don’t remember where I got the link from.  But I do know when.  That was when nuget was out and I had no way of retrieving missing packages.  Since then, I run this script to our local NAS from time to time.

The Powershell Source

# --- settings ---
$feedUrlBase = ""
# the rest will be params when converting to funclet
$latest = $true
$overwrite = $false
$top = 1500 #use $top = $null to grab all or a number to get TOP 500 packages
# $destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "NuGetLocal"
$destinationDirectory = "L:\TEMP\NuGetLocal"

# --- locals ---
$webClient = New-Object System.Net.WebClient

# --- functions ---

# download entries on a page, recursively called for page continuations
function DownloadEntries {
param ([string]$feedUrl)
$feed = [xml]$webClient.DownloadString($feedUrl)
$entries = $feed.feed.entry
$progress = 0
foreach ($entry in $entries) {
    $url = $entry.content.src
    $fileName = $ + "." + $ + ".nupkg"
    $saveFileName = join-path $destinationDirectory $fileName
    $pagepercent = ((++$progress)/$entries.Length*100)
    if ((-not $overwrite) -and (Test-Path -path $saveFileName))
        write-progress -activity "$fileName already downloaded" `
                       -status "$pagepercent% of current page complete" `
                       -percentcomplete $pagepercent
    write-progress -activity "Downloading $fileName" `
                   -status "$pagepercent% of current page complete" `
                   -percentcomplete $pagepercent

    [int]$trials = 0
    do {
        try {
            $trials +=1
            $webClient.DownloadFile($url, $saveFileName)
        } catch [System.Net.WebException] {
            write-host "Problem downloading $url `tTrial $trials `
                       `n`tException: " $_.Exception.Message
    while ($trials -lt 3)

  $link = $ | where { $_.rel.startsWith("next") } | select href
  if ($link -ne $null) {
    # if using a paged url with a $skiptoken like
    # http:// ... /Packages?$skiptoken='EnyimMemcached-log4net','2.7'
    # remember that you need to escape the $ in powershell with `
    return $link.href
  return $null

# the NuGet feed uses a fwlink which redirects
# using this to follow the redirect
function GetPackageUrl {
param ([string]$feedUrlBase)
$resp = [xml]$webClient.DownloadString($feedUrlBase)
return $resp.service.GetAttribute("xml:base")

# --- do the actual work ---

# if dest dir doesn't exist, create it
if (!(Test-Path -path $destinationDirectory)) {
    New-Item $destinationDirectory -type directory

# set up feed URL
$serviceBase = GetPackageUrl($feedUrlBase)
$feedUrl = $serviceBase + "Packages"
if($latest) {
    $feedUrl = $feedUrl + "?`$filter=IsLatestVersion eq true"
    if($top -ne $null) {
        $feedUrl = $feedUrl + "&`$orderby=DownloadCount desc&`$top=$top"

while($feedUrl -ne $null) {
    $feedUrl = DownloadEntries $feedUrl

Umbraco and embedded macro scripts

by Damiaan Peeters 11. January 2013 08:58

It is possible to use Embedded macro scripts in master pages.  You know:

<umbraco:Macro runat=”server” language=”cshtml”>

I’ve seen a lot of these chunks of code in masterpages.  Although you might LOVE Razor, there is no reason for you to do this!   

First of all, you could solve the previous line simple with a <umbraco:Item /> tag in your master page.  Secondly, Umbraco released version 4.10 with MVC capabilities. So you don’t need to use the Masterpages anyway.  Do you? Thirdly, u can still use inline code.  I know the documentation says it’s not a recommended way, but it’s fast and for easy master page related things I think perfectly fine. <% if(condition) umbraco.NodeFactory.Node.GetCurrent().GetProperty(…).Value %> This doesn’t involve a creation overhead for each Razor macro which is being called.

But here are my personal reasons why I don’t like them:

  • Visual studio problems: if coding embedded macro’s in visual studio you have
    • no intellisense
    • bad syntax highlighting
    • impossible errors & bizar warnings
    • automatic formatting shortcut screws up everything. In VS, you can use CTRL + K , CTRL + D to format your code automatically. Your embedded macro’s will probably screws up regularly.
  • Hard(er) to configure cache parameters.  Did you ever tried to cache by page or by member?
  • Having to macro’s running next to each other:

    <umbraco:Macro runat="server" language="cshtml">
  • You can’t set a break point and really DEBUG what might be going wrong in your code.
  • When you ARE debugging
    • you end up in separate files and you do not know which masterpage you are exactly debugging
    • you can and will change - by accident – temporary generated razor scripts

Most of the time I use these rules on how we use Razor Macro’s in Umbraco:

  • Create separate files in the MacroScripts folder. 
  • If performance is importance convert Model to DynamicNode instead of working with DLR objects
  • Add @Inherits & @using umbraco.MacroEngines  to optimize Visual Studio Experience
  • Use Helpers where possible
  • Extend @Library or create own extensions in App_Code or even better: a custom .Net dll with your code precompiled
  • Choose between @umbraco.library.GetDictionaryItem(“theDictKey”) and @Dictionary.theDictKey and don’t use both.
  • Follow coding standards which are normally applied in normal .Net code.  For razor I prefer { on the same line (see post of scottgu introducing Razor).  But don’t mix!
  • If you really need an embedded macro and want a break point, use  @{                System.Diagnostics.Debugger.Break(); }

Oh.  And check out the umbraco development guidelines on our, they are there for you to read.

What do you think?  Do you agree?  What are your best practices for umbraco and Razor macro’s.

Find that big database in SQL server

by Damiaan Peeters 10. January 2013 20:08

We have several SQL databases.  Each for each client website.  We also have a lot of servers running SQL server.  When you need to clean up space, you sometimes know that there is just one big database . 

sp_helpdb to the rescue! 


And when you add a database name to sp_help ‘my_db_name’
you get all the files too…



SQL | Sysadmin

Certified Umbraco Master, Part of Umbraco Certified partner comm-it, .Net and Azure developer, seo lover. Magician in my spare time.

Month List