Sweet, but not edible
Chris Alcock
@calcock http://TheMorningBrew.NET/
• 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
• .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
2010
• Currently version 1.3
http://www.nuget.org
http://www.outercurve.org
http://nuget.codeplex.com
• 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
• Makes getting and installing packages easy
• Nice IDE Integration
• Provides means of finding and distributing packages
• Deals with more than just .NET assemblies
• Supports projects targeting different runtime versions and platforms
• Rich installation and scripting support
• http://www.nuget.org
• Provides official source of NuGet
Packages
• Package publishing, ownership and community functions
• Package Stats – http://stats.nuget.org
Demonstration
Using NuGet as a package consumer (GUI)
Demonstration
Installing & Uninstalling Packages via Console
• Steps:
– Write your library / Code
– Define Package Specification, Files to be included, etc
– Build the package
– Publish
– Consume
• Shortcuts and Tooling makes some of this easy
• Can’t do it with the Extension alone
• Get NuGet.Exe from CodePlex
• NuGet Package Explorer is also really useful
• Both available from http://nuget.codeplex.com/releases
• NuGet Packages can contain:
– Assemblies
– Content Files
– Configuration
– Scripts
• Uses convention over configuration
• Nuget isn’t just useful for distributing
.NET Assemblies
• Can also package:
– JavaScript libraries
– Samples
– Scripts
• Any Tools or files are possible
Demonstration
Making a Package (or 2)
• 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
Demonstration
Package Management Console
OR
PowerShell Console
• 3 Special PowerShell Scripts in NuGet
– Init.ps1
– Install.ps1
– Uninstall.ps1
• Scripts located in Tools package folder
• Have access to Environment via parameters:
– $installPath, $toolsPath, $package, $project
Demonstration
PowerShell In Packages
• 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
Demonstration
Using WebActivator in your packages
• NuGet Packages can add commands to
Package Management Console
• Implement as Standard PowerShell
Functions / Modules
• Register using Init.ps1 NuGet Script
Demonstration
Extending IDE
• 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
• Configure sources in Package Manager Settings
• Choose Source in console
• Use –Source <Source> in Nuget.exe
• Easiest to set up
• Works over network drives too
• Add your own packages or pull in public packages
Demonstration
Own Packages in Directory
• 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:
– http://scou.se/~Gxn
Demonstration
Hosting Read Only
• 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 – http://scou.se/~Gxx
• .NET 4
• IIS
– 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
• Main Site: http://nuget.org
• Documentation: http://docs.nuget.org
• Project: http://nuget.codeplex.com
• Mix11 – Scott Hanselman & Phil Haack – NuGet In Depth http://scou.se/~Gyw
• TechEd North America 11 – Scott Hanselman - NuGet:
Microsoft .NET Package Management for the Enterprise http://scou.se/~Gyx
• NuGet Gallery Project: http://nuggetgallery.codeplex.com
• Orchard Project: http://www.orchardproject.net/
• These slides will be online http://cwa.me.uk
• PowerPoint Template Based on http://www.templateswise.com/detail/link-174.html