NuGet - Chris Alcock

advertisement

NuGet

Sweet, but not edible

Chris Alcock

@calcock http://TheMorningBrew.NET/

Shameless Plug…

• http://TheMorningBrew.NET

• Daily .NET news from the Blog’o’sphere:

– Latest Software Releases

– Best Articles

– UK Community news

Agenda

• 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

2010

• Currently version 1.3

http://www.nuget.org

http://www.outercurve.org

http://nuget.codeplex.com

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 packages

• Deals with more than just .NET assemblies

• Supports projects targeting different runtime versions and platforms

• Rich installation and scripting support

Package Gallery

• 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

Packaging Your Wares

• 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

Packaging Your Wares

• 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

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

Demonstration

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

Demonstration

Package Management Console

OR

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 parameters:

– $installPath, $toolsPath, $package, $project

Demonstration

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

Demonstration

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

Demonstration

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 console

• 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 packages

Demonstration

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:

– http://scou.se/~Gxn

Demonstration

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 – http://scou.se/~Gxx

NuGet Gallery Requirements

• .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

Demonstration

Your Own Gallery

Summary

• 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: 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

Download