NuGet - Chris Alcock

Sweet, but not edible
Chris Alcock
Shameless Plug…
• http://TheMorningBrew.NET
• Daily .NET news from the Blog’o’sphere:
– Latest Software Releases
– Best Articles
– UK Community news
• What is NuGet, What’s it all about?
• Using NuGet as a package consumer
• Creating your own packages
– Simple Package creation
– Advanced Package creation
• Embracing the Package Manager Console
• Configuring package sources
What Is NuGet?
.NET Package Manager
Originally Nu / NuPack, renamed to NuGet
Shipped With ASP.NET MVC3
Open Source – Part of Outercurve Foundation,
hosted on CodePlex
• In Top 5 New Open Source Project to Watch
• Currently version 1.3
Package Management?!?!?
• Tools to make it easy to obtain, install and
update libraries
• Influenced by other Package Managers:
– Apt-Get - Linux
– Gems - Ruby
– HornGet - .NET
• Other .NET Packages Managers exists
– OpenWrap
How NuGet Helps…
• Makes getting and installing packages easy
• Nice IDE Integration
• Provides means of finding and distributing
• Deals with more than just .NET assemblies
• Supports projects targeting different
runtime versions and platforms
• Rich installation and scripting support
Package Gallery
• Provides official source of NuGet
• Package publishing, ownership and
community functions
• Package Stats –
Using NuGet as a package consumer (GUI)
Installing & Uninstalling Packages via Console
Packaging Your Wares
• Steps:
– Write your library / Code
– Define Package Specification, Files to be included,
– Build the package
– Publish
– Consume
• Shortcuts and Tooling makes some of this easy
Packaging Your Wares
• Can’t do it with the Extension alone
• Get NuGet.Exe from CodePlex
• NuGet Package Explorer is also really
• Both available from
Parts of NuGet Package
• NuGet Packages can contain:
– Assemblies
– Content Files
– Configuration
– Scripts
• Uses convention over configuration
Other Uses for Packaging
• Nuget isn’t just useful for distributing
.NET Assemblies
• Can also package:
– JavaScript libraries
– Samples
– Scripts
• Any Tools or files are possible
Making a Package (or 2)
So What Else?
• NuGet Package Console IS PowerShell
• Gives easiest way to do command line
operations on your VS projects
• PowerShell’s inclusion provides
scripting capabilities for packages
Package Management Console
PowerShell Console
PowerShell In Packages
• 3 Special PowerShell Scripts in NuGet
– Init.ps1
– Install.ps1
– Uninstall.ps1
• Scripts located in Tools package folder
• Have access to Environment via
– $installPath, $toolsPath, $package, $project
PowerShell In Packages
Web Start-Up Code
• Simple way to enable start-up of your
library in Web Apps
• WebActivator NuGet library
• Replacements of the
[PreApplicationStartMethod] and
[PostApplicationStartMethod] attributes
which were included in .NET 4
Using WebActivator in your packages
Extending IDE w/ PowerShell
• NuGet Packages can add commands to
Package Management Console
• Implement as Standard PowerShell
Functions / Modules
• Register using Init.ps1 NuGet Script
Extending IDE
Package Sources
• The NuGet Extension supports multiple
Package Sources in a hierarchy
• Problems if One source is down
• Three ways to add your own:
– Local Directories
– Read Only Server
– Your Own Gallery
Working with Multiple Sources
• Configure sources in Package Manager Settings
• Choose Source in
• Use –Source <Source>
in Nuget.exe
Directory Source
• Easiest to set up
• Works over network drives too
• Add your own packages or pull in public
Own Packages in Directory
Hosting Web Based Read Only
• Next Logical Step, moving closer to the full
gallery experience
• Made possible using a NuGet Package
– NuGet.Server
• It’s a web application, so you can add to it,
read more about that here:
Hosting Read Only
Your Own Gallery
• NuGet official Gallery is based on Orchard CMS
• All Open Source – can create your own
• Gives full fidelity
Create packages and publish to gallery
Browse Gallery
Manage your packages
Extend or integrate with your own requirements
• Great set of instructions online on the NuGet
Documentation site –
NuGet Gallery Requirements
• .NET 4
– 2 Hosts, Gallery and Gallery Service
• SQL Server Express / SQL Server
– 2 databases & suitable authentication
• Mercurial
• MSBuild in your Path
• ~1.3GB Disk Space
Your Own Gallery
• Explored package consumption
• Built packages in a variety of ways
• Seen how PowerShell can be used in
the IDE
• Looked at the options for managing
your own NuGet Feed
Further Information & Questions
Main Site:
Mix11 – Scott Hanselman & Phil Haack – NuGet In Depth
TechEd North America 11 – Scott Hanselman - NuGet:
Microsoft .NET Package Management for the Enterprise
NuGet Gallery Project:
Orchard Project:
These slides will be online -
PowerPoint Template Based on

similar documents