Introduction to NuGet

Try as it might, it's impossible for Microsoft to provide every possible piece of code a developer could need. There are millions of developers on the .NET platform, each with unique technical and business problems to solve. Waiting on Microsoft to solve every problem just doesn't scale, nor make sense.

The good news is that many of these developers are “scratching their own itch” by writing useful libraries that solve their own problems and the problems of their peers. They're also distributing these libraries on the Web, often as a free download or under an open source license.

With all these useful libraries out there in the wild, the challenge becomes finding one of the libraries and making proper use of it in your project, not to mention tracking updates for all the libraries you've incorporated.

This section walks through a quick example of the steps it took before NuGet to grab the ELMAH library. ELMAH stands for Error Logging Module and Handler and is a very useful library for logging and displaying unhandled exception information within a web application.

These are the steps it takes to make use of it:

1. You have to find ELMAH. Due to its unique name, this is easy with any search engine.

2. Download the correct zip package. Multiple zip files are presented, and as I personally learned, choosing the correct one isn't always trivial.

3. “Unblock” the package. Files downloaded from the Web are marked with information specifying that they came from the “web zone” and are potentially unsafe. This mark is sometimes referred to as the “Mark of the Web.” It's important to unblock the zip file before you expand it, otherwise every file within has the bit set and your code won't work in certain cases. If your curious about how this mark is set, read up on the Attachment Manager in Windows which is responsible for protecting the OS from potentially unsafe attachments http://support.microsoft.com/kb/883260.

4. Verify its hash against the one provided by the hosting environment. You do verify the hash of the file with the one listed in the download page to ensure that it hasn't been altered, don't you? Don't you?!

5. Unzip the package contents into a known location. Typically, this will be placed in a lib folder so you can reference the assembly. Developers typically don't want to add assemblies directly to the bin directory because they don't want to add the bin directory to source control.

6. Add an assembly reference. Add a reference to the assembly in the Visual Studio Project.

7. Update web.config. ELMAH requires a bit of configuration. Typically, you'll have to go searching the documentation to find the correct settings.

All these steps for a library, ELMAH, that has no dependencies!

And if the library does have dependencies, every time you update the library, you'll need to find the correct version of each dependency, repeating each of the previous steps for each dependency. This is a painful set of tasks to undertake every time you are ready to deploy a new version of your application, which is why many teams just stick with old versions of their dependencies for a long time.

This is the pain that NuGet solves. NuGet automates all these common and tedious tasks for a package as well as its dependencies. It removes nearly all of the challenges of incorporating a third-party open source library into a project's source tree. Of course, using that library properly is still up to the developer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.168