In the last few years, NuGet has gone from being a poorly understood Visual Studio extension to the definitive tool for component-based development (CBD) in the Microsoft dev-ecosystem.
In this webinar, we’ll examine NuGet with a critical eye and detail best practices for its use, avoiding its pitfalls, and crafting its place in your CBD tool chain. Along the way we'll highlight how best to use it with Perforce, which is uniquely well suited to be the foundation of your own component-based development with NuGet.
5. What is NuGet?
• YAPM: Yet Another Package Manager
• Packages are zip archives
• Originally .NET, now anything
• Discovery, packages, dependencies, updates
Controlling Component Chaos
with NuGet and Versioning
6. How Does It Work?
• Web site/service describes packages
• NuGet.exe and VisualStudio extension:
– Makes packages from specs
– Pulls packages by ID and version
– Pushes packages to publish
Controlling Component Chaos
with NuGet and Versioning
7. Nuget.org web site
NuGet package feed
(AtomPub)
Controlling Component Chaos
with NuGet and Versioning
NuGet Extension
NuGet.exe Tool
NuGet Diagram
11. Managing Packages in a Solution
Controlling Component Chaos
with NuGet and Versioning
12. How Does It Work?
• Adds new build targets
• Pulls and unzips packages
• Creates/updates configuration files
• Hooks up dependencies
• Runs installer scripts (if any)
Controlling Component Chaos
with NuGet and Versioning
13. Some Obvious Questions
• How does NuGet track what I’m using?
• How do others get the same packages?
• Do I need to add it to my build process?
Controlling Component Chaos
with NuGet and Versioning
14. NuGet Folders and Files
Controlling Component Chaos
with NuGet and Versioning
16. What Do I Version?
• All packages.config files
• The .nuget folder contents
• Nothing else needs to be versioned
Controlling Component Chaos
with NuGet and Versioning
17. Component Versions
• Pulls by semantic version
• Update process prefers latest
• Default strategy updates dependencies too
• Update must be used carefully
Controlling Component Chaos
with NuGet and Versioning
18. Perforce Tips
• Prefer implicit checkout
• Reconcile before and after
• P4 ignore is your friend
• Be sure to use P4VS
• Isolate big NuGet operations
Controlling Component Chaos
with NuGet and Versioning
20. But I Prefer Explicit Checkout!
• Problems installing/updating
• Mark as edit ahead of time
• Seek masochist support group
Controlling Component Chaos
with NuGet and Versioning
21. DevOps Considerations
• Clean to catch old references
• Different feeds for different builds
• Automate third-party package audits
• Scripting catches multiple versions
Controlling Component Chaos
with NuGet and Versioning
23. Some Assembly Required
• Privacy requires your own NuGet server
• Organizational shift in thinking
• Good naming conventions early
• Understand semantic versioning
Controlling Component Chaos
with NuGet and Versioning
24. Some Obvious Questions
• How do I make my own packages?
• Where do I put them?
• And how do I put them there?
Controlling Component Chaos
with NuGet and Versioning
25. Building a Package
• The *.nuspec file
– Useful metadata
– Content and layout
– Other package dependencies
• NuGet tool creates package
• Push with a new version number
Controlling Component Chaos
with NuGet and Versioning
26. Development Best Practices
• Understand semantic versioning
• Develop components in isolation
• Careful interface design and versioning
• Unit test at least every public method
• Document all public symbols
Controlling Component Chaos
with NuGet and Versioning
27. DevOps Considerations
• Automate push on release and documentation
• Automate labelling for traceability
• Source/symbol serving is your friend
• Version all the things! (if you wish)
Controlling Component Chaos
with NuGet and Versioning
28. Gotchas and Q&A
Controlling Component Chaos
with NuGet and Versioning
29. Common Gotchas
• Pre-configure Visual Studio
• Relative paths for source server
• NuGet extension problem with P4VS
• Update versioning strategy
• Soft dependencies can hurt
Controlling Component Chaos
with NuGet and Versioning
30. THANK YOU!!!
John Williston, Ph.D
jwilliston@perforce.com
@p4jbw
Controlling Component Chaos
with NuGet and Versioning
P4Ideax Forums
Editor's Notes
The NuGet Package Explorer is a handy, open-source tool for viewing packages: http://npe.codeplex.com/
A NuGet feed includes data that’s obvious and not so obvious. A good article on working with the API is “”Fun With NuGet Web API” at: http://chris.eldredge.io/blog/2013/02/25/fun-with-nuget-rest-api/
The main NuGet web site lets you browse and search for packages easily. See http://www.nuget.org for details.
Here we see the details for the latest stable release of Entity Framework, and the command line in the middle can be run from the package manager console to install it without touching the GUI tool.
To get to the tool, simply right click your solution in the explorer window and choose the option to manage NuGet packages. Over on the left you can see options to switch between packages already installed in your solution/projects, packages available online, and any updates, all of which are grouped by known feeds. The center shows the resulting list and the pane on the right shows details.
In the folder tree on the left we can see both the .nuget and packages folders underneath the solution folder, which is where NuGet will create them. On the right we see two horizontal panes, the top of which shows the contents of the .nuget folder, the bottom of which shows a packages.config file in the context of a REST API web application.
Here we see the contents of a packages.config file, each XML package element corresponding to a NuGet package.
More information on semantic versioning at http://semver.org
You can get the Perforce Visual Studio Plug-in at: http://www.perforce.com/product/components/visual-studio-plug-in
Completely cleaning the working folder on your build server will delete the packages folder as long as you don’t version it. This will result in NuGet pulling down all the packages at build time, which will expose references to old versions, which can otherwise result in multiple versions of the same assembles being included in the same project(s), and that is the way of pain.
A popular NuGet server with symbol support is NuPeek: https://bitbucket.org/thinkbeforecoding/nupeek
The NuGet Package Explorer is a handy, open-source tool for viewing packages: http://npe.codeplex.com/
VS2010 needs to have NuGet installed, whereas VS2012 and later shipped with it right out of the box. Pre-configuring your internal feed sources will also help on-board new developers. The NuGet extension for Visual Studio uses two different code paths for file operations, only one of which lets our P4VS plugin know what’s happening. We’re aware of the bug and hope to work with the NuGet community for a resolution. Until that time, be sure to reconcile after any significant NuGet operation to catch files of which P4VS wasn’t notified. NuGet doesn’t handle soft dependencies well; it wants to add a reference to every library included. And then Visual Studio will “helpfully” strip them away during build, package, and deploy.