Nuget

It is easier than you think and you should be using it

Ever needed to share an assembly or code?

Needed to setup configuration for your shared assembly?

Don't know who you to contact when you have a new version?

Questioned if you even have the latest version?

Found a bug and don't know who to contact?

Nuget solves all of these problems 

  • Easy way to distribute assemblies, code, and configure files.
     

  • Handles:

    • Packaging

    • Dependency Management

    • Versioning

    • Hosting

Nuget Provides

  • Public Gallery
    http://nuget.org/packages
     

  • Public Feed
    https://nuget.org/api/v2
     

  • Any Nuget feed Url
     

  • Any folder Path or network share

Getting Packages

  • Downloads Package


  • Download & Install Missing Dependencies
     

  • Install Package
     

  • packages.config updated in project dir

Using Package 

  • If updating, uninstall executed
     

  • Assemblies added as reference
     

  • Files/Directories added 
     

  • Config/Source Files transformed
     

  • Powershell scripts executed

Install Means?

  • Don't check in Nuget packages
     

  • In Visual Studio, before build missing packages are download
     

  • For automated builds, run nuget restore in sln dir

Package Restore

  • UI Overview
     

  • Command Line Overview
     

  • Consuming Packages
     

  • Restoring Packages

Demo Time

Creating Packages

  • Overview

  • Package Conventions

  • Supporting Multiple Frameworks

  • Creating a Package

Creating Topics

  • Projects (csproj/vbproj)
     

  • Assembly (dll)
     

  • Directory

Create Packages From

  • Assemblies
     

  • Source Code
     

  • Powershell scripts
     

  • Executables
     

  • Config Files

Packages Can Contain

  • Overview

  • Package Conventions

  • Supporting Multiple Frameworks

  • Creating a Package

Creating Topics

  • Nuget uses convention over configuration
     

  • One Package per assembly
     

  • Package ID and Version identifiers in Feed
     

  • Version normally version # of assembly

Package Conventions

  • Standard Directories:

    • tools

    • lib

    • content

    • build

Package Conventions

  • Overview

  • Package Conventions

  • Supporting Multiple Frameworks

  • Creating a Package

Creating Topics

  • Target any .NET profile
     

  • Examples:

    • lib\net20

    • lib\net40-client
       

  • Empty folder means do nothing for version

Multiple Frameworks

  • Overview

  • Package Conventions

  • Supporting Multiple Frameworks

  • Creating a Package

Creating Topics

Nuget Command Line

$ nuget spec MyAssembly.dll
 

$ nuget pack MyAssembly.nuspec

From an Assembly

$ nuget spec -> from project file directory

 

$ nuget pack MyProject.csproj

From A Project File

$ nuget spec package.id

 

$ nuget pack package.id.nuspec

From A Directory

Nuget Spec Non-VS

<id>log4net.blank.config</id>
<version>1.0.0</version>
<title>
    Log4Net Blank Configuration File
</title>
<authors>Justin James</authors>
<owners>Justin James</owners>
<description>
    Inserts a blank log4net.config file.
</description>

Nuget Spec VS

<id>$id$</id>
<version>$version$</version>
<title>
    $title$
</title>
<authors>$author$</authors>
<owners>$author$</owners>
<description>
    $description$
</description>
  • General Options

    • OutputDirectory
       

  • Visual Studio Project Options

    • IncludeReferencedProjects

    • Prop Configuration=Release

    • Build

 

Common Pack Options

  • Nuget Package Explorer

    • Create new packages

    • View existing packages

    • Download existing package

    • Free

    • Download at http://npe.codeplex.com/

Gui to Create Packages

  • Creating a Nuget package
     

  • Nuget Package Explorer Demo

Demo Time

Hosting Your

Own Feed

  • Any Directory on your computer 
     

  • Any File Share on the network

Directory Based Feed

  • Hosted in IIS
     

  • Use the nuget.server package

Hosted Feed

  • Create nuget.config File in sln dir
     

  • Add your feed url to nuget.config
     

  • Nuget will automatically use nuget.config

Tell People About Feed

  • Creating Remote Feed
     

  • Adding a New Package Source
     

  • Nuget.config File

Demo

Nuget 3.0

  • Coming out as part of VS 2015
     

  • Most package manager console features available in GUI
     

  • No longer a modal dialog

Nuget 3.0

Revisit Consuming Demo

 

BUT NO

 

Package Manager Console!

Demo

  • No longer worry about distributing your dlls
     

  • Config setup distributed with your dll
     

  • Automatic alerting of new versions
     

  • Alway be assured you are on latest release
     

  • Each package has contact information

Recap

thank you

i'm Justin.

 

@digitaldrummerj - digitaldrummerj@gmail.com

http://digitaldrummerj.me

BACKUP

  • Overview

  • Supporting Multiple Frameworks

  • Basic Package Creation

  • Updating Configuration Files

  • Including Source Code Files

  • Install/Uninstall Scripts

Topics

  • Include

    • a [filename].transform

    • a [filename].install.xdt

    • a [filename].uninstall.xdt

Update Config Files

  • Utilizes XDT syntax

  • Allows manipulation of elements

    • Add

    • Remove

    • Modify

[Filename].*.xdt

  • Contains Xml that looks like config

  • Contains Only Sections to Be Merged

  • Only adds elements

  • Does not modify existing elements 

  • Merged elements removed on uninstall

[Filename].Transform

  • Overview

  • Supporting Multiple Frameworks

  • Basic Package Creation

  • Updating Configuration Files

  • Including Source Code Files

  • Install/Uninstall Scripts

Topics

  • [filename].cs.pp

  • Works somewhat like project templates

  • Any project property may be replaced 

    • Example: $rootnamespace$

Source File Transforms

  • Overview

  • Supporting Multiple Frameworks

  • Basic Package Creation

  • Updating Configuration Files

  • Including Source Code Files

  • Install/Uninstall Scripts

Topics

  • Located in tools directory

  • 3 Files:

    • Init.ps1

    • Install.ps1

    • Uninstall.ps1

(un)Install Scripts

  • Runs 1st time package is installed
     

  • Runs every time solution is opened
     

  • Has to be in root of tools folder else ignored

Init.ps1

  • Runs Each time package is installed
     

  • Must have files in content or lib folders
     

  • Runs after Init.ps1

Install.ps1

  • Runs when package is uninstalled or updated

Uninstall.ps1

  • Top of each file

    • param($installPath, $toolsPath, $package, $project)
       

  • Helper Package:

    • NuGetPSVariables

Parameters

  • Install / Uninstall Powershell Scripts

  • NuGetPsVariables

Demo Time

Nuget

By Justin James

Nuget

Teaching you how to use NuGet and why you should use it.

  • 1,738
Loading comments...

More from Justin James