Nuget is easier than you thinkNuget is easier than you think
andand
you should be using it.you should be using it.
By
Justin James
About MeAbout Me
My name is Justin James. I'm a software craftsman building applications
in ASP.NET and C# at Intel. I have been using .NET since the 1.0 beta days.
You can find all of my presentations at
http://www.slides.com/digitaldrummerj
Code Demos
github.com/digitaldrummerj/NugetTalk
Follow me on twitter
@digitaldrummerj
TopicsTopics
Nuget Feature Overview
Consuming Packages
Creating Packages
Advanced Creating Packages
Hosting your own package feed
Other Projects using Nuget
More Information
Quick SurveyQuick Survey
How many of you have consumed a nuget package?
How many of you have created your own nuget packages?
How many have hosted your own nuget package feed?
What is the heck Nuget?What is the heck Nuget?
Package Manager for .NET
Way to easily share libraries, code, configurations
GUI is integrated into Visual Studio
or
Available as command line
Package format is a nupkg file
Similar to npm or bower in the node/angular world.
Note: Powershell 2.0 is required.
Where can I get nuget packages?Where can I get nuget packages?
Public Gallery: http://www.nuget.org/packages
Public Feed: https://www.nuget.org/api/v2/
A package source can be any URL or folder path
You can have multiple sources configured
What happens when I consume aWhat happens when I consume a
package?package?
1. Looks at package dependencies to figure out what is installed
2. Downloads any missing dependencies and installs them
3. Downloads package and installs it
4. package.config file created in project folder
5. repositories.config file is created in the packages folder
Note: The packages are store in a packages folder within the same
directory as the <Your Solution>.sln
What does install a package mean?What does install a package mean?
1. If package is used before then Uninstall.ps1 is run
2. References, Source Files, and Config changes are removed
3. A folder for each package is created in the package folder
4. Package is uncompressed
5. Any dll in the lib folder is added as a reference
6. Anything in the content folder are copied into the project
7. Files with a .pp extensions are transformed into source files
8. Xml files with a .transform extension are merged
9. Xml files with a (un)install.xdt are transformed
10. Init.ps1 is run
11. Install.ps1 is run
Note: Powershell scripts are optional
What happens when I build aWhat happens when I build a
solution?solution?
From within visual studio
Missing packages will automatically be downloaded before the 1st project
is built
Using MSBuild:
run nuget.exe restore in the sln directory to download missing packages
Note: This feature is called package restore
DemoDemo
UI Overview
Nuget Commands Overview
Consuming Packages
Package Restore
Creating Packages TopicsCreating Packages Topics
Basic Package Creation
Supporting Multiple Frameworks
Update Configuration Files
Include Source Code
Install/Uninstall Scripts
Creating Packages OverviewCreating Packages Overview
Can create from a project, assembly or directory
May contain:
assemblies, source code, powershell scripts, executables, config files,
config/source transformations
Most packages are project level
but you can create solution level packages.
Can support multiple .NET framework Versions and Profiles
If publishing package publicly, need a free account at http://nuget.org/
Solution level PackagesSolution level Packages
Installs a tool or additional commands for the Package Manager console
Does not add references, content, or build customizations to any projects
in your solution.
A package is considered a solution-level package if it and it dependencies
do not contain any files in its lib, content, or build directories.
Tracked in a packages.config file in the .nuget directory, rather than in a
packages.config file in a specific project.
Example: psake package
Package ConventionsPackage Conventions
Nuget uses convention over configuration approach
In general, have one package per assembly.
Package ID and Version are the identifiers used in the package feed
Version is normally the version number of the assembly
Standard Directories:
Tools - powershell scripts and programs accessible from PM
lib - Assemblies are added as references during install
content - files to copy to root of your project during install
build - MSBuild targets that are inserted into project file
Supporting Multiple FrameworksSupporting Multiple Frameworks
supports multiple frameworks in same package
can target any .NET profiles (client, full, compact)
Framework name is case sensitive
naming convention is
[lib/content/tools]{framework}{version}
Examples :
libnet20 to support .NET 2.0
libnet40-client to support .NET 4.0 client profile
Note: empty folder indicates don't do anything for that version
Basic Package CreationBasic Package Creation
Download nuget command line
Put nuget.exe into your path
Generate from assembly
nuget spec MyAssembly.dll
nuget pack MyAssembly.nuspec
Generate from project file
nuget spec -> from the project file dir
nuget pack MyProject.csproj
Generate from convention based directory
nuget spec package.id
nuget pack package.id.nuspec
Example Nuget Spec Non-VSExample Nuget Spec Non-VS
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>log4net.blank.config</id>
<version>1.0.0</version>
<title>Log4Net Blank Configuration File</title>
<authors>Justin James</authors>
<owners>Justin James</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Inserts a blank log4net.config file.</description>
<summary>Log4Net Blank Configuration File</summary>
<releaseNotes>Initial Rev</releaseNotes>
<dependencies>
<dependency id="log4net" version="2.0.3" />
</dependencies>
</metadata>
<files>
<file src="**" exclude="build.cmd" />
</files>
</package>
Example Nuget Spec - VSExample Nuget Spec - VS
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes> Summary of changes made in this release.</releaseNotes>
<copyright>Copyright 2014</copyright>
<tags>Demo</tags>
</metadata>
</package>
Common Nuget Pack OptionsCommon Nuget Pack Options
Against Visual Studio Project:
-IncludeReferencedProjects
-Prop Configuration=Release
-Build
-OutputDirectory control where the nupkg is saved to.
Using a GUI to create packagesUsing a GUI to create packages
Not everyone wants to use the command line to create package.
The is the GUI use for package creation.Nuget Package Explorer
Install using Chocolatey or http://npe.codeplex.com/
Questions on Creation Basics?Questions on Creation Basics?
Coming Up:
Updating Configuration Files
Including Source Code
Powershell Scripts
2 ways to update configs files2 ways to update configs files
Include a [filename].transform is xml based like a config file
or
Utilize XDT Transforms with
[filename].install.xdt
[filename].uninstall.xdt
[Filename].transform[Filename].transform
- contains XML that looks like config
- contains only sections to be merged.
- only adds elements or adds attributes
- does not change existing elements or attributes
- merged elements/attributes are removed on uninstall
[Filename].*.xdt[Filename].*.xdt
- utilizes the XDT syntax
same syntax as web.config.debug/release
- Allows manipulating of the structure instead of just merge
- xdt:Locator element that you want to change
- xdt:Transform what to do to the elements
- Insert, InsertIfMissing, InsertAfter, InsertBefore, SetAttributes
- Remove, RemoveAll, RemoveAttributes
http://msdn.microsoft.com/en-us/library/dd465326.aspx
Transform Source CodeTransform Source Code
[filename].cs.pp
- works somewhat like project templates
- any project property may be replace in .pp file
- property name surrounded by $
example: $rootnamespace$
http://msdn.microsoft.com/en-
us/library/vslangproj.projectproperties_properties(VS.80).aspx
Powershell ScriptsPowershell Scripts
Files should be located in the tools directory
Init.ps1
- run the 1st time package is installed into solution
- runs every time solution is opened in Visual Studio
- has to be in root of tools folder else will be ignored
Install.ps1
- run each time package is installed into a project
- must have files in content or lib folders to run
- runs after Init.ps1
Uninstall.ps1
- run each time package is uninstalled or updated
Powershell Scripts Cont.Powershell Scripts Cont.
Add this line at top of each file:
param($installPath, $toolsPath, $package, $project)
$installPath - path to the folder where package is installed
$toolsPath - path to tools directory
$package - reference to the package object
$project - reference to EnvDTE project object and null in Init.ps1
Helper Package to see values: NuGetPsVariables
- writes above values to log file and then uninstall itself
DemoDemo
Creating a nuget package from the command line.
Creating same package using Gui instead.
Config / Source Transforms
Install / Uninstall Powershell Scripts
Testing XDT Transforms
Script to Increment Package Version
NuGetPsVariables
Hosting Your Own Nuget FeedHosting Your Own Nuget Feed
Local Feed: point at a folder on your system
Remote Feeds: You can host a remote feed on a server that runs IIS.
Can also host nuget gallery locally
Setting up a Local Gallery
Branding the Nuget Gallery
Tell Everyone about the FeedTell Everyone about the Feed
Create a Nuget.Config file
Defines nuget configuration includes sources.
Loads from the default location
then loads any file named NuGet.config starting
from the root of the current drive
and ending in the current directory.
Default Location: %AppData%NugetNuget.Config
Docs: docs.nuget.org/docs/reference/nuget-config-file
DemoDemo
Creating Remote Feed
Adding new package source
Nuget.config overview
Updating nugetUpdating nuget
Visual Studio Tools -> Extensions and Updates
Command Line -> nuget update -self
Nuget vNext (aka 3.0)Nuget vNext (aka 3.0)
Totally redesigned UI
Consolidated installed/online/updates views together
Version selection for installs/updates within UI
WhatIf available in the UI
Control over dependency version selection
Open for multiple projects at once
Ability to leave UI open
http://blog.nuget.org/20141014/in-the-platform.html
Now available in Visual Studio 2015
Other projects using nugetOther projects using nuget
Chocolatey - windows package manager
BoxStarter - uses chocolatey. better way to setup new machine
Resharper Extension Manager - uses custom NuGet Gallery
JetBrains TeamCity - consume, create, publish tasks
MyGet - NuGet server to create/host you own feeds.
OctopusDeploy - convention-based automated deployment
SymbolSource - debug packages by downloading symbols/source
More InformationMore Information
Main NuGet Web Site and Package Repository
http://nuget.org/
Documentation
http://docs.nuget.org/
NuGet Team Blog
http://blog.nuget.org/
Apps Built On Top of Nuget
http://docs.nuget.org/docs/reference/ecosystem
Twitter Feed of Latest Packages
https://twitter.com/NuGetLatest
BooksBooks
Pro NuGet ( )Amazon Link
Nuget 2 Essentials ( )Amazon Link
Questions?Questions?
Blog: digitaldrummerj.azurewebsites.net
Email: digitaldrummerj at gmail.com
Twitter: @digitaldrummerj
Slides: http://www.slides.com/digitaldrummerj
BackupBackup
What does a nupkg do?What does a nupkg do?
Includes everything necessary to install a library or tool
Installs package dependencies
Can copy files to your solution
Can add references
Can update app.config / web.config
Can run powershell scripts
On uninstall, removes files, and reverses changes made in the project
3 ways to play with packages3 ways to play with packages
For Whole Solution:
Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution
For Project:
In Solution Explorer -> Right-click on project -> select Manage Nuget
Packages
Powershell Based
Tools -> Nuget Package Manager -> Package Manager Console
Spec Replacement TokensSpec Replacement Tokens
$id$ -The Assembly Name
$version$ - version specified in the AssemblyVersion attribute
$author$ - company in the AssemblyCompany attribute
$description$ - description in the AssemblyDescription attribute
$configuration$ - build configuration (debug/release)
Getting HelpGetting Help
All of nuget's documentation: http://docs.nuget.org/
Package Manager Command Help
get-help nuget -> gets available nuget commands
get-help [nuget command] -> get specific command help
common help parameters:
-examples
-detailed
-full
-online
Installing PackagesInstalling Packages
In Solution Explorer:
Right click on project or solution
Select Manage Nuget Packages
Select Online-> All or specific source
Select for the package you want
Click Install (Always installs latest version)
In Package Manager Console:
Install-Package [Package Name]
Install-Package [Package Name] -Version [Version #]
Common CommandsCommon Commands
Manage Nuget Packages for Solution
List / Search
Install
Update
Uninstall
PM Console Commands
Install-Package
Update-Package
Uninstall-Package
Get-Package
Updating PackagesUpdating Packages
In Solution Explorer:
Right click on project or solution
Select Manage Nuget Packages
Select Updates -> All or specific source
In Package Manager Console:
Update-Package [Package Name] -> Specific Package
Update-Package -> All packages
Warning: Update-Package with no parameters will update each package
to latest version regardless of dependency version.
Warning #2: Update uninstalls previous version before install
Uninstall PackageUninstall Package
In Solution Explorer:
Right click on project or solution
Select Manage Nuget Packages
Select Installed Packages
Select Package to Uninstall
Click Uninstall
In Package Manager Console:
Uninstall-Package [Package Name]
Note: You can not delete packages that are a dependency to another
package
Re-Install PackagesRe-Install Packages
Best accomplished in the package manager console
In Manage Nuget Packages:
Would have to uninstall package and then go install package
In Package Manager Console:
The -Reinstall switch will uninstall and install package(s) including
dependencies.
Update-Package [Package Name] -Reinstall -> Specific Package
Update-Package -Reinstall -> All packages
Framework and ProfilesFramework and Profiles
Framework:
.NET Framework -> net
Silverlight -> sl
.NET Micro Framework -> netmf
Windows Phone 8 -> windowsphone8
Profiles:
Client -> client
Windows Phone 7 -> wp
Compact Framework -> cf
Full -> full
Framework Versions ExamplesFramework Versions Examples
.NET 3.5 -> net35
.NET 4.0 -> net40
.NET 3.5 Client - net35-client
.NET 4.0 Full -> net40-full
Silverlight 3 -> sl3
windows phone 8 -> windowsphone8
Portable Class Library for Windows Store App & .NET 4.5 -> portable-
windows8+net45
Full Docs
Useful PM Console SwitchesUseful PM Console Switches
-ProjectName -> specific projects to take action on
-Version -> version of package to use. default latest
-WhatIf -> displays the actions that would be taken
-Source -> specifics url or directory path to use
Publishing PackagesPublishing Packages
nuget setapikey [Api Key]
nuget push <package path> [API Key] [options]
Options:
-Source
-ApiKey
-Timeout
Default source is nuget.org unless specified or DefaultPushSource in
NuGet config file is set (%AppData%NugetNuget.config)
Hosting Remote Feed in AzureHosting Remote Feed in Azure
http://suchan.cz/2014/10/how-to-deploy-your-own-nuget-server-on-
azure-website-in-15-minutes/
or
http://bit.ly/11K6vMG
Include/Exclude FilesInclude/Exclude Files
<files>
<file src="" target="" exclude="" />
</files>
src -> location of files.
* wildcard is allowed.
** wildcard recursive directory search.
target -> relative path to put files into
exclude -> file(s) to exclude.
can contain semi-colon delimited list or file pattern
can use * and ** wildcards
DependenciesDependencies
<dependencies>
<dependency id="" version="" />
</dependencies>
id -> package id
version -> package version
Can be grouped by Framework by putting in
<group targetFramework=""></group>
if framework blank, acts as like the flat file list
Note: can either be grouped or flat but not mixed.
Assembly ReferencesAssembly References
<references>
<reference file="xunit.dll" />
</references>
Assemblies in the lib directory to add to the project reference list.
works just like dependencies with either flat list or grouped.
Can be grouped by Framework by putting in
<group targetFramework=""></group>
if framework blank, acts as like the flat file list
Note: can either be grouped or flat but not mixed.
Framework Assembly ReferencesFramework Assembly References
You can also reference Framework assemblies that are installed in the
GAC
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.ServiceModel"
targetFramework="net40" />
<frameworkAssembly assemblyName="System.SomethingElse" />
</frameworkAssemblies>
Can specify multiple frameworks by separating by comma
if left blank, always add
UI PreviewUI Preview

Nuget is easier than you think and you should be using it as both a consumer and creator of packages

  • 1.
    Nuget is easierthan you thinkNuget is easier than you think andand you should be using it.you should be using it. By Justin James
  • 2.
    About MeAbout Me Myname is Justin James. I'm a software craftsman building applications in ASP.NET and C# at Intel. I have been using .NET since the 1.0 beta days. You can find all of my presentations at http://www.slides.com/digitaldrummerj Code Demos github.com/digitaldrummerj/NugetTalk Follow me on twitter @digitaldrummerj
  • 3.
    TopicsTopics Nuget Feature Overview ConsumingPackages Creating Packages Advanced Creating Packages Hosting your own package feed Other Projects using Nuget More Information
  • 4.
    Quick SurveyQuick Survey Howmany of you have consumed a nuget package? How many of you have created your own nuget packages? How many have hosted your own nuget package feed?
  • 5.
    What is theheck Nuget?What is the heck Nuget? Package Manager for .NET Way to easily share libraries, code, configurations GUI is integrated into Visual Studio or Available as command line Package format is a nupkg file Similar to npm or bower in the node/angular world. Note: Powershell 2.0 is required.
  • 6.
    Where can Iget nuget packages?Where can I get nuget packages? Public Gallery: http://www.nuget.org/packages Public Feed: https://www.nuget.org/api/v2/ A package source can be any URL or folder path You can have multiple sources configured
  • 7.
    What happens whenI consume aWhat happens when I consume a package?package? 1. Looks at package dependencies to figure out what is installed 2. Downloads any missing dependencies and installs them 3. Downloads package and installs it 4. package.config file created in project folder 5. repositories.config file is created in the packages folder Note: The packages are store in a packages folder within the same directory as the <Your Solution>.sln
  • 8.
    What does installa package mean?What does install a package mean? 1. If package is used before then Uninstall.ps1 is run 2. References, Source Files, and Config changes are removed 3. A folder for each package is created in the package folder 4. Package is uncompressed 5. Any dll in the lib folder is added as a reference 6. Anything in the content folder are copied into the project 7. Files with a .pp extensions are transformed into source files 8. Xml files with a .transform extension are merged 9. Xml files with a (un)install.xdt are transformed 10. Init.ps1 is run 11. Install.ps1 is run Note: Powershell scripts are optional
  • 9.
    What happens whenI build aWhat happens when I build a solution?solution? From within visual studio Missing packages will automatically be downloaded before the 1st project is built Using MSBuild: run nuget.exe restore in the sln directory to download missing packages Note: This feature is called package restore
  • 10.
    DemoDemo UI Overview Nuget CommandsOverview Consuming Packages Package Restore
  • 11.
    Creating Packages TopicsCreatingPackages Topics Basic Package Creation Supporting Multiple Frameworks Update Configuration Files Include Source Code Install/Uninstall Scripts
  • 12.
    Creating Packages OverviewCreatingPackages Overview Can create from a project, assembly or directory May contain: assemblies, source code, powershell scripts, executables, config files, config/source transformations Most packages are project level but you can create solution level packages. Can support multiple .NET framework Versions and Profiles If publishing package publicly, need a free account at http://nuget.org/
  • 13.
    Solution level PackagesSolutionlevel Packages Installs a tool or additional commands for the Package Manager console Does not add references, content, or build customizations to any projects in your solution. A package is considered a solution-level package if it and it dependencies do not contain any files in its lib, content, or build directories. Tracked in a packages.config file in the .nuget directory, rather than in a packages.config file in a specific project. Example: psake package
  • 14.
    Package ConventionsPackage Conventions Nugetuses convention over configuration approach In general, have one package per assembly. Package ID and Version are the identifiers used in the package feed Version is normally the version number of the assembly Standard Directories: Tools - powershell scripts and programs accessible from PM lib - Assemblies are added as references during install content - files to copy to root of your project during install build - MSBuild targets that are inserted into project file
  • 15.
    Supporting Multiple FrameworksSupportingMultiple Frameworks supports multiple frameworks in same package can target any .NET profiles (client, full, compact) Framework name is case sensitive naming convention is [lib/content/tools]{framework}{version} Examples : libnet20 to support .NET 2.0 libnet40-client to support .NET 4.0 client profile Note: empty folder indicates don't do anything for that version
  • 16.
    Basic Package CreationBasicPackage Creation Download nuget command line Put nuget.exe into your path Generate from assembly nuget spec MyAssembly.dll nuget pack MyAssembly.nuspec Generate from project file nuget spec -> from the project file dir nuget pack MyProject.csproj Generate from convention based directory nuget spec package.id nuget pack package.id.nuspec
  • 17.
    Example Nuget SpecNon-VSExample Nuget Spec Non-VS <?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> <metadata> <id>log4net.blank.config</id> <version>1.0.0</version> <title>Log4Net Blank Configuration File</title> <authors>Justin James</authors> <owners>Justin James</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Inserts a blank log4net.config file.</description> <summary>Log4Net Blank Configuration File</summary> <releaseNotes>Initial Rev</releaseNotes> <dependencies> <dependency id="log4net" version="2.0.3" /> </dependencies> </metadata> <files> <file src="**" exclude="build.cmd" /> </files> </package>
  • 18.
    Example Nuget Spec- VSExample Nuget Spec - VS <?xml version="1.0"?> <package > <metadata> <id>$id$</id> <version>$version$</version> <title>$title$</title> <authors>$author$</authors> <owners>$author$</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>$description$</description> <releaseNotes> Summary of changes made in this release.</releaseNotes> <copyright>Copyright 2014</copyright> <tags>Demo</tags> </metadata> </package>
  • 19.
    Common Nuget PackOptionsCommon Nuget Pack Options Against Visual Studio Project: -IncludeReferencedProjects -Prop Configuration=Release -Build -OutputDirectory control where the nupkg is saved to.
  • 20.
    Using a GUIto create packagesUsing a GUI to create packages Not everyone wants to use the command line to create package. The is the GUI use for package creation.Nuget Package Explorer Install using Chocolatey or http://npe.codeplex.com/
  • 21.
    Questions on CreationBasics?Questions on Creation Basics? Coming Up: Updating Configuration Files Including Source Code Powershell Scripts
  • 22.
    2 ways toupdate configs files2 ways to update configs files Include a [filename].transform is xml based like a config file or Utilize XDT Transforms with [filename].install.xdt [filename].uninstall.xdt
  • 23.
    [Filename].transform[Filename].transform - contains XMLthat looks like config - contains only sections to be merged. - only adds elements or adds attributes - does not change existing elements or attributes - merged elements/attributes are removed on uninstall
  • 24.
    [Filename].*.xdt[Filename].*.xdt - utilizes theXDT syntax same syntax as web.config.debug/release - Allows manipulating of the structure instead of just merge - xdt:Locator element that you want to change - xdt:Transform what to do to the elements - Insert, InsertIfMissing, InsertAfter, InsertBefore, SetAttributes - Remove, RemoveAll, RemoveAttributes http://msdn.microsoft.com/en-us/library/dd465326.aspx
  • 25.
    Transform Source CodeTransformSource Code [filename].cs.pp - works somewhat like project templates - any project property may be replace in .pp file - property name surrounded by $ example: $rootnamespace$ http://msdn.microsoft.com/en- us/library/vslangproj.projectproperties_properties(VS.80).aspx
  • 26.
    Powershell ScriptsPowershell Scripts Filesshould be located in the tools directory Init.ps1 - run the 1st time package is installed into solution - runs every time solution is opened in Visual Studio - has to be in root of tools folder else will be ignored Install.ps1 - run each time package is installed into a project - must have files in content or lib folders to run - runs after Init.ps1 Uninstall.ps1 - run each time package is uninstalled or updated
  • 27.
    Powershell Scripts Cont.PowershellScripts Cont. Add this line at top of each file: param($installPath, $toolsPath, $package, $project) $installPath - path to the folder where package is installed $toolsPath - path to tools directory $package - reference to the package object $project - reference to EnvDTE project object and null in Init.ps1 Helper Package to see values: NuGetPsVariables - writes above values to log file and then uninstall itself
  • 28.
    DemoDemo Creating a nugetpackage from the command line. Creating same package using Gui instead. Config / Source Transforms Install / Uninstall Powershell Scripts Testing XDT Transforms Script to Increment Package Version NuGetPsVariables
  • 29.
    Hosting Your OwnNuget FeedHosting Your Own Nuget Feed Local Feed: point at a folder on your system Remote Feeds: You can host a remote feed on a server that runs IIS. Can also host nuget gallery locally Setting up a Local Gallery Branding the Nuget Gallery
  • 30.
    Tell Everyone aboutthe FeedTell Everyone about the Feed Create a Nuget.Config file Defines nuget configuration includes sources. Loads from the default location then loads any file named NuGet.config starting from the root of the current drive and ending in the current directory. Default Location: %AppData%NugetNuget.Config Docs: docs.nuget.org/docs/reference/nuget-config-file
  • 31.
    DemoDemo Creating Remote Feed Addingnew package source Nuget.config overview
  • 32.
    Updating nugetUpdating nuget VisualStudio Tools -> Extensions and Updates Command Line -> nuget update -self
  • 33.
    Nuget vNext (aka3.0)Nuget vNext (aka 3.0) Totally redesigned UI Consolidated installed/online/updates views together Version selection for installs/updates within UI WhatIf available in the UI Control over dependency version selection Open for multiple projects at once Ability to leave UI open http://blog.nuget.org/20141014/in-the-platform.html Now available in Visual Studio 2015
  • 34.
    Other projects usingnugetOther projects using nuget Chocolatey - windows package manager BoxStarter - uses chocolatey. better way to setup new machine Resharper Extension Manager - uses custom NuGet Gallery JetBrains TeamCity - consume, create, publish tasks MyGet - NuGet server to create/host you own feeds. OctopusDeploy - convention-based automated deployment SymbolSource - debug packages by downloading symbols/source
  • 35.
    More InformationMore Information MainNuGet Web Site and Package Repository http://nuget.org/ Documentation http://docs.nuget.org/ NuGet Team Blog http://blog.nuget.org/ Apps Built On Top of Nuget http://docs.nuget.org/docs/reference/ecosystem Twitter Feed of Latest Packages https://twitter.com/NuGetLatest
  • 36.
    BooksBooks Pro NuGet ()Amazon Link Nuget 2 Essentials ( )Amazon Link
  • 37.
    Questions?Questions? Blog: digitaldrummerj.azurewebsites.net Email: digitaldrummerjat gmail.com Twitter: @digitaldrummerj Slides: http://www.slides.com/digitaldrummerj
  • 38.
  • 39.
    What does anupkg do?What does a nupkg do? Includes everything necessary to install a library or tool Installs package dependencies Can copy files to your solution Can add references Can update app.config / web.config Can run powershell scripts On uninstall, removes files, and reverses changes made in the project
  • 40.
    3 ways toplay with packages3 ways to play with packages For Whole Solution: Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution For Project: In Solution Explorer -> Right-click on project -> select Manage Nuget Packages Powershell Based Tools -> Nuget Package Manager -> Package Manager Console
  • 41.
    Spec Replacement TokensSpecReplacement Tokens $id$ -The Assembly Name $version$ - version specified in the AssemblyVersion attribute $author$ - company in the AssemblyCompany attribute $description$ - description in the AssemblyDescription attribute $configuration$ - build configuration (debug/release)
  • 42.
    Getting HelpGetting Help Allof nuget's documentation: http://docs.nuget.org/ Package Manager Command Help get-help nuget -> gets available nuget commands get-help [nuget command] -> get specific command help common help parameters: -examples -detailed -full -online
  • 43.
    Installing PackagesInstalling Packages InSolution Explorer: Right click on project or solution Select Manage Nuget Packages Select Online-> All or specific source Select for the package you want Click Install (Always installs latest version) In Package Manager Console: Install-Package [Package Name] Install-Package [Package Name] -Version [Version #]
  • 44.
    Common CommandsCommon Commands ManageNuget Packages for Solution List / Search Install Update Uninstall PM Console Commands Install-Package Update-Package Uninstall-Package Get-Package
  • 45.
    Updating PackagesUpdating Packages InSolution Explorer: Right click on project or solution Select Manage Nuget Packages Select Updates -> All or specific source In Package Manager Console: Update-Package [Package Name] -> Specific Package Update-Package -> All packages Warning: Update-Package with no parameters will update each package to latest version regardless of dependency version. Warning #2: Update uninstalls previous version before install
  • 46.
    Uninstall PackageUninstall Package InSolution Explorer: Right click on project or solution Select Manage Nuget Packages Select Installed Packages Select Package to Uninstall Click Uninstall In Package Manager Console: Uninstall-Package [Package Name] Note: You can not delete packages that are a dependency to another package
  • 47.
    Re-Install PackagesRe-Install Packages Bestaccomplished in the package manager console In Manage Nuget Packages: Would have to uninstall package and then go install package In Package Manager Console: The -Reinstall switch will uninstall and install package(s) including dependencies. Update-Package [Package Name] -Reinstall -> Specific Package Update-Package -Reinstall -> All packages
  • 48.
    Framework and ProfilesFrameworkand Profiles Framework: .NET Framework -> net Silverlight -> sl .NET Micro Framework -> netmf Windows Phone 8 -> windowsphone8 Profiles: Client -> client Windows Phone 7 -> wp Compact Framework -> cf Full -> full
  • 49.
    Framework Versions ExamplesFrameworkVersions Examples .NET 3.5 -> net35 .NET 4.0 -> net40 .NET 3.5 Client - net35-client .NET 4.0 Full -> net40-full Silverlight 3 -> sl3 windows phone 8 -> windowsphone8 Portable Class Library for Windows Store App & .NET 4.5 -> portable- windows8+net45 Full Docs
  • 50.
    Useful PM ConsoleSwitchesUseful PM Console Switches -ProjectName -> specific projects to take action on -Version -> version of package to use. default latest -WhatIf -> displays the actions that would be taken -Source -> specifics url or directory path to use
  • 51.
    Publishing PackagesPublishing Packages nugetsetapikey [Api Key] nuget push <package path> [API Key] [options] Options: -Source -ApiKey -Timeout Default source is nuget.org unless specified or DefaultPushSource in NuGet config file is set (%AppData%NugetNuget.config)
  • 52.
    Hosting Remote Feedin AzureHosting Remote Feed in Azure http://suchan.cz/2014/10/how-to-deploy-your-own-nuget-server-on- azure-website-in-15-minutes/ or http://bit.ly/11K6vMG
  • 53.
    Include/Exclude FilesInclude/Exclude Files <files> <filesrc="" target="" exclude="" /> </files> src -> location of files. * wildcard is allowed. ** wildcard recursive directory search. target -> relative path to put files into exclude -> file(s) to exclude. can contain semi-colon delimited list or file pattern can use * and ** wildcards
  • 54.
    DependenciesDependencies <dependencies> <dependency id="" version=""/> </dependencies> id -> package id version -> package version Can be grouped by Framework by putting in <group targetFramework=""></group> if framework blank, acts as like the flat file list Note: can either be grouped or flat but not mixed.
  • 55.
    Assembly ReferencesAssembly References <references> <referencefile="xunit.dll" /> </references> Assemblies in the lib directory to add to the project reference list. works just like dependencies with either flat list or grouped. Can be grouped by Framework by putting in <group targetFramework=""></group> if framework blank, acts as like the flat file list Note: can either be grouped or flat but not mixed.
  • 56.
    Framework Assembly ReferencesFrameworkAssembly References You can also reference Framework assemblies that are installed in the GAC <frameworkAssemblies> <frameworkAssembly assemblyName="System.ServiceModel" targetFramework="net40" /> <frameworkAssembly assemblyName="System.SomethingElse" /> </frameworkAssemblies> Can specify multiple frameworks by separating by comma if left blank, always add
  • 57.