Geeks With Blogs
Josh Reuben

Why Nuget

A higher level of granularity for managing references

When you have solutions of many projects that depend on solutions of many projects etc à escape from Solution Hell.


· Using A GUI (Package Explorer) to build packages -

· Creating a Nuspec File -

· consuming a Nuget Package -

· Nuspec reference -

· updating packages -

· versioning -

POC Folder Structure


POC Setup Steps

· Install package explorer

· Source

o Create a source solution – configure output directory for projects (Project > Properties > Build > Output Path)

· Package

o Add assemblies to package from output directory (D&D)- add net folder


o File > Export – save .nuspec files and lib contents

<?xml version="1.0" encoding="utf-16"?>
<package xmlns="">
<title />
<owners />
<description>My package description.</description>
<summary />

o File > Save – saves .nupkg file

· Create Target Solution

o In Tools > Options: Configure package source & Add package



Select projects:


Output from package manager (powershell console)

------- Installing...MyPackage 1.0.0 -------

Added file 'NugetSource.AssemblyA.dll' to folder 'MyPackage.1.0.0\lib'.

Added file 'NugetSource.AssemblyA.pdb' to folder 'MyPackage.1.0.0\lib'.

Added file 'NugetSource.AssemblyB.dll' to folder 'MyPackage.1.0.0\lib'.

Added file 'NugetSource.AssemblyB.pdb' to folder 'MyPackage.1.0.0\lib'.

Added file 'MyPackage.1.0.0.nupkg' to folder 'MyPackage.1.0.0'.

Successfully installed 'MyPackage 1.0.0'.

Added reference 'NugetSource.AssemblyA' to project 'AssemblyX'

Added reference 'NugetSource.AssemblyB' to project 'AssemblyX'

Added file 'packages.config'.

Added file 'packages.config' to project 'AssemblyX'

Added file 'repositories.config'.

Successfully added 'MyPackage 1.0.0' to AssemblyX.


o Packages folder created at solution level

o Packages.config file generated in each project:

<?xml version="1.0" encoding="utf-8"?>


  <package id="MyPackage" version="1.0.0" targetFramework="net40" />


A local Packages folder is created for package versions installed:


Each folder contains the downloaded .nupkg file and its unpacked contents – eg of dlls that the project references

Note: this folder is not checked in


o Configure Package Manager to automatically check for updates


o Browse packages - It automatically picked up the updates


Update Procedure

· Modify source

· Change source version in assembly info

· Build source

· Open last package in package explorer

· Increment package version number and re-add assemblies

· Save package with new version number and export its definition

· In target solution – Tools > Manage Nuget Packages – click on All to trigger refresh , then click on recent packages to see updates

· If problematic, delete packages folder


uninstall-package mypackage

install-package mypackage –version

uninstall-package mypackage

install-package mypackage –version


· clip_image018

<?xml version="1.0" encoding="utf-16"?>
<package xmlns="">
<title />
<owners />
<description>My package description.</description>
<group targetFramework=".NETFramework4.0">
<dependency id="MyPackage" version="" />

Using NuGet without committing packages to source control

Right click on the Solution node in Solution Explorer and select Enable NuGet Package Restore.


— Recall that packages folder is not part of solution


If you get downloading package ‘’ failed, config proxy to support certificate for & allow unrestricted access to

To test connectivity: get-package –listavailable

To test Nuget Package Restore – delete packages folder and open vs as admin.

In nugget msbuild:

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

TFSBuild Integration

Modify Nuget.Targets file

<RestorePackages Condition="  '$(RestorePackages)' == '' ">



<PackageSource Include="\\IL-CV-004-W7D\Packages" />

Add System Environment variable EnableNuGetPackageRestore=true & restart the “visual studio team foundation build service host” service.


Important: Ensure Network Service has access to Packages folder

Nugetter TFS Build integration

Add Nugetter build process templates to TFS source control

For Build Controller - Specify location of custom assemblies


Generate .nuspec file from Package Explorer: File > Export


Edit the file elements – remove path info from src and target attributes

<?xml version="1.0" encoding="utf-16"?>

<package xmlns="">




        <title />


        <owners />


        <description>My package description.</description>


            <group targetFramework=".NETFramework3.5" />




        <file src="CommonTypes.dll" target="CommonTypes.dll" />

        <file src="CommonTypes.pdb" target="CommonTypes.pdb" />

Add .nuspec file to solution so that it is available for build:



Add a Build Process Definition based on the Nugetter build process template:


Configure the build process – specify:

· .sln to build

· Base path (output directory)

· Nuget.exe file path

· .nuspec file path



Copy DLLs to a binary folder

1) Set copy local for an assembly reference to false

2)  MSBuild Copy Task – modify .csproj file:

    <MySourceFiles Include="$(MSBuildProjectDirectory)\..\SourceAssemblies\**\*.*" />
  <Target Name="BeforeBuild">
    <Copy SourceFiles="@(MySourceFiles)" DestinationFolder="bin\debug\SourceAssemblies" />

3) Set Probing assembly search path from app.config - -                

<?xml version="1.0" encoding="utf-8" ?>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="SourceAssemblies"/>

Forcing 'copy local = false'

The following generic powershell script was added to the packages install.ps1:

param($installPath, $toolsPath, $package, $project)
if( $project.Object.Project.Name -ne "CopyPackages")
$asms = $package.AssemblyReferences | %{$_.Name}
foreach ($reference in $project.Object.References)
if ($asms -contains $reference.Name + ".dll")
$reference.CopyLocal = $false;

An empty project named "CopyPackages" was added to the solution - it references all the packages and is the only one set to CopyLocal="true". No MSBuild knowledge required.


Posted on Sunday, September 23, 2012 12:39 PM | Back to top

Comments on this post: Real World Nuget

# re: Real World Nuget
Requesting Gravatar...
Great idea! This is a relevant information today. - Dr. Thomas G. Devlin MD, PhD
Left by Robert Jacob on Dec 28, 2016 1:00 PM

Your comment:
 (will show your gravatar)

Copyright © JoshReuben | Powered by: