Exercise 2: Consuming NuGet Packages

In this exercise, you will learn how to consume external libraries in your project by using NuGet public repositories. You will be able to add any packaged library from the cloud into your project.

With that goal in mind, in this exercise you will add an ELMAH (Error Logging Modules and Handlers) Library to your project, enabling you to see the error log generated by the library.

Note:
is a pluggable library for error and exception logging that can be dynamically added to an ASP.NET web application.

To read more about ELMAH, see this article at msdn.

Task 1 – Consuming an External Library from Visual Studio 2010 NuGet Extension

In this task, you will include ELMAH library into your project to add an error log.

  1. Open the begin solution at Source\Ex02-Consuming and Packing NuGet\Begin\MvcMusicStore.
  2. From Solution Explorer, open References folder and right-click to add Library Package Reference.

    Figure 1

    NuGet Tool – Adding a package reference

  3. Select ELMAH from the package list and click Install.

    Figure 2

    NuGet Tool – Installing a package reference

  4. Figure 3

    Package Manager Options – Elmah Library added to the solution

    Figure 4

    Project folder– Elmah Library download location

Task 2 – Running the Solution

  1. In this task, you will run the solution to see ELMAH log working:
  2. Press F5 to run MvcMusicStore solution.
  3. Browse an inexistent URL like /test. You should see a “The resource cannot be found” error message.
  4. Browse /elmah.axd to see the log that will include a line for the error logged when browsing an inexistent URL:

    Figure 5

    Elmah Library log view

Next Step

Summary