![Page 1: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/1.jpg)
![Page 2: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/2.jpg)
Laat ons weten wat u vindt van deze sessie! Vul de evaluatie in via www.techdaysapp.nl en maak kans op een van de 20 prijzen*. Prijswinnaars worden bekend gemaakt via Twitter (#TechDaysNL). Gebruik hiervoor de code op uw badge.
Let us know how you feel about this session! Give your feedback via www.techdaysapp.nl and possibly win one of the 20 prizes*. Winners will be announced via Twitter (#TechDaysNL). Use your personal code on your badge.
* Over de uitslag kan niet worden gecorrespondeerd, prijzen zijn voorbeelden – All results are final, prizes are examples
![Page 3: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/3.jpg)
Using NuGetthe way you shouldMaarten Balliauw@maartenballiauw
![Page 4: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/4.jpg)
Who am I?
• Maarten Balliauw• Antwerp, Belgium• Technical Evangelist, JetBrains• Founder, MyGet• AZUG• Focus on web
• ASP.NET MVC, Azure, SignalR, ...• MVP Azure & ASPInsider
• Big passion: Azure• http://blog.maartenballiauw.be • @maartenballiauw Shameless self promotion: Pro NuGet - http://amzn.to/pronuget2
![Page 5: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/5.jpg)
Agenda
• NuGet• File | New Project…• The state of NuGet• Every project is a package• Creating packages• Distributing packages• Consuming packages
![Page 6: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/6.jpg)
NuGet
![Page 7: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/7.jpg)
A brief NuGet introduction...
• Package management system for .NET• Visual Studio extension, command line, console
• Simplifies incorporating 3rd party libraries• Developer focused• Free, open source
• Use packages from the official feed• Publish your own packages• Create & use your own feed
![Page 8: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/8.jpg)
File | New Project...
![Page 9: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/9.jpg)
DemoFile | New Project...
![Page 10: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/10.jpg)
That was trouble!
•Dependencies on NuGet packages•Dependencies on projects•Dependencies on file system layout•Breaking changes in dependencies
Dependency hell
![Page 11: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/11.jpg)
“Dependencies, also in real life, are trouble. Have you ever had to depend on a plumber?”- Maarten Balliauw
![Page 12: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/12.jpg)
Dependencies before NuGet
•Projects in solution•Reference in-house projects:
• Either the assemblies (typically unversioned / all 1.0.0.0)
• Either the actual project / linked files (unversioned by design)
•Reference third party assemblies (e.g. JSON.NET)
![Page 13: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/13.jpg)
Dependencies with NuGet
•Projects in solution•Reference in-house projects:
• Either the assemblies (typically unversioned / all 1.0.0.0)• Either the actual project / linked files (unversioned by design)
•Reference third party packages (e.g. JSON.NET)• Semantic Versioning to announce breaking changes
(happy times as long as package authors respect that)
![Page 14: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/14.jpg)
The state of NuGet
![Page 15: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/15.jpg)
The state of NuGet
•We are consumers!• Even quite some overconsumption I dare say…
•We sort of know about Semantic Versioning• If the mayor version changes, we’re doomed
•Are we producing?• Some are, e.g. OSS and some companies
•Did we solve our dependency issues?
Where are we, 3 years in?
![Page 16: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/16.jpg)
.NET is late to the party!
•Others have been doing package management for decades• Perl (CPAN.org)• Linux (RPM/YUM/APT-GET/...)• PHP (PEAR, Composer)• Node (npm)• Ruby (Gems)
•We can learn a great deal from these!
![Page 17: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/17.jpg)
What are the others doing?{ "name" : "IniTech.Framework.Formatters", "version" : "1.0.0 ", "author" : "Maarten Balliauw", "bugs" : { "url" : "https://github.com/initech/framework-formatters/issues" }, "description" : "Formatters specific to the IniTech organization.", "homepage" : "https://github.com/initech/framework-formatters", "keywords" : [ "framework", "formatters", "initech" ], "license" : "Proprietary", "main" : "index.js", "repository" : { "type" : "git", "url" : "https://github.com/initech/framework-formatters" }, "scripts" : { "test" : "echo \"Error: no test specified\" && exit 1" }, "dependencies" : { "date-format" : "0.0.2", "format" : "~0.2.1", "moment" : "~2.5.1" }}
![Page 18: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/18.jpg)
What are the others doing?
•Name and version of the project•Dependencies (and version range) of the project
•Every project is a package!• It can have dependencies• It can be depended on
What was in that package.json?
![Page 19: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/19.jpg)
Every project is a package
![Page 20: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/20.jpg)
Supporting componentization
•Every project is a package• Clearly identifyable• Proper Semantic Versioning
•Every project becomes discoverable• Nice description, release notes, ...• Add it to a private feed so developers can find it
•Dependencies (can) stay out of source control•Dependencies are versioned
![Page 21: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/21.jpg)
But… NuGet only has packages.config!
•Nodejs: packages.json•Composer (PHP): composer.json•NuGet:
• packages.config: dependencies• <projectname>.nuspec: package description• NuGet.config: other settings• It’s 2-3 files in our world, but it is all there.
•Let’s become producers!
![Page 22: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/22.jpg)
“Project referencesmust die.”- Maarten Balliauw
![Page 23: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/23.jpg)
Creating packages
![Page 24: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/24.jpg)
All we need is one file
•XML file which can be generated• nuget.exe spec• Install-Package NuSpec && Install-Nuspec
•Run nuget.exe pack to create package
<projectname>.nuspec
![Page 25: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/25.jpg)
DemoCreating packages
![Page 26: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/26.jpg)
Think about versioning!
• www.semver.org
• SemVer states intentions• It’s the only way toavoid dependencyversioning hell.But not bullet-proof.
Enforce Explicit Semantic Versioning
Major Breaking changes
Minor Backwards compatible changese.g. API additions
Patch Bugfixes not affecting the API<dependency id="ExamplePackage" version="1.3.2" />
1.0 = 1.0 ≤ x(,1.0] = x ≤ 1.0(,1.0) = x < 1.0[1.0] = x == 1.0(1.0) = invalid(1.0,) = 1.0 < x(1.0,2.0) = 1.0 < x < 2.0[1.0,2.0] = 1.0 ≤ x ≤ 2.0empty = latest version
![Page 27: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/27.jpg)
Distributing packages
![Page 28: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/28.jpg)
Which medium?
• In source control (please don’t)
• Local / network folder (slow > ~50 packages)
• NuGet.Server (slow > ~50 packages)
• NuGet Gallery (clone of www.nuget.org)• MyGet (www.myget.org, SaaS) • ProGet (www.inedo.com/proget)• TeamCity NuGet artifacts (www.jetbrains.com/teamcity)
We will need a “package source” or feed
![Page 29: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/29.jpg)
How do they get there?
•Manual upload•As part of our continuous integration process• All benefits of CI (e.g. testing)• Plus reporting on which packages we are using• Plus publishing packages for consumption
![Page 30: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/30.jpg)
DemoContinuous Integration& Distributing Packages with TeamCity
![Page 31: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/31.jpg)
What did we just see?
•Creating packages using .nuspec•NuGet configuration inheritance•Continuous Integration on TeamCity
• How to run package restore• How to build a package• How to see packages that are being used
•How to consume a package
![Page 32: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/32.jpg)
NuGet configuration inheritance
•Make settings common to projects!• NuGet walks up the directory tree to find NuGet.config files
•Or even push them to developer machines• %AppData%\NuGet\NuGet.config• %ProgramData%\NuGet\Config\*.config• ...
•See http://bit.ly/nuget-config-inheritance •Configure feeds, proxy, credentials, ...
![Page 33: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/33.jpg)
More recommendations…
•Don’t just update blindly• Not everyone respects SemVer…• It would take us back to the original problem
•Don’t autoupdate during builds• Continuous Integration: Same Input = Same Output• Be explicit about versioning
![Page 34: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/34.jpg)
Deploying from NuGet packages
•Using a simple, handcrafted script•Using a tool like OctopusDeploy.com
• Which is even cooler combined with Chocolatey.org
•TeamCity supports various ways of deploying (e.g. WebDeploy)
![Page 35: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/35.jpg)
DemoDeploying packaged applicationswith a handcrafted script
![Page 36: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/36.jpg)
Considerations
•TeamCity internal NuGet feed• Only build artifacts
• No way to add external packages that are being used• May not be a problem for your setup
• But maybe it is: a feed is much like source control for dependencies
• Add dependencies that are being used, NuGet.org, component vendors, ...
• If it is, create your own feed, e.g. MyGet.org
![Page 37: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/37.jpg)
Create a package source / feed
•That’s a cool library! And that one too!• Avoid overconsumption by limiting packages• May not block developers but at least the build will fail
•Your own feed will only contain packages you know• Keep versions under control• Keep licensing under control• Easy way to audit external packages in use
For your team or the entire organization
![Page 38: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/38.jpg)
DemoPushing packages from TeamCity
![Page 39: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/39.jpg)
Conclusions
![Page 40: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/40.jpg)
Conclusions
• NuGet• File | New Project…• The state of NuGet• Every project is a package• Creating packages• Distributing packages• Consuming packages
What have we learned?
![Page 41: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/41.jpg)
“Stop just consuming NuGet packages. Re-think your development by also creating them. It’s a logical evolution.”- Maarten Balliauw
![Page 42: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/42.jpg)
Thank you!http://blog.maartenballiauw.be@maartenballiauwhttp://amzn.to/pronuget
![Page 43: Using NuGet the way you should - TechDays NL 2014](https://reader036.vdocuments.site/reader036/viewer/2022062405/554f8e08b4c905d25b8b5041/html5/thumbnails/43.jpg)
Laat ons weten wat u vindt van deze sessie! Vul de evaluatie in via www.techdaysapp.nl en maak kans op een van de 20 prijzen*. Prijswinnaars worden bekend gemaakt via Twitter (#TechDaysNL). Gebruik hiervoor de code op uw badge.
Let us know how you feel about this session! Give your feedback via www.techdaysapp.nl and possibly win one of the 20 prizes*. Winners will be announced via Twitter (#TechDaysNL). Use your personal code on your badge.
* Over de uitslag kan niet worden gecorrespondeerd, prijzen zijn voorbeelden – All results are final, prizes are examples