Getting Started
NuGet, in essence, is a Visual Studio extension that comes bundled with Visual Studio 2012 or newer. A lot of value comes from NuGet’s integration with Visual Studio or the Visual Studio Express editions. Taking advantage of this integration offers you a seamless development workflow and enables you to work with NuGet right from within your Visual Studio installation; you’ll even have a nice user interface to work with.
Dedicating an entire chapter to installing NuGet is probably overkill since NuGet already comes bundled with recent editions of Visual Studio. In short, all you need to have is Visual Studio 2012 (any edition) or Visual Studio 2013. From Visual Studio, use the Tools ä Extensions and Updates menu to update the NuGet Visual Studio extension to its latest version.
Not everyone is making use of the latest version of Visual Studio, which is why we’ll have a look at how to install NuGet into Visual Studio 2010.
Apart from the NuGet Visual Studio extension, there are several other tools you may want to have installed on your system when reading this book and trying out some of the examples. NuGet also comes as a command-line tool, which can be used as a stand-alone feature. A tool like NuGet Package Explorer is not part of Visual Studio, yet it’s a great addition to our developer toolbox when working with NuGet. So before we elaborate on working with NuGet from within Visual Studio in Chapter 2, this chapter will help you prepare your workstation and get all the prerequisites to work with NuGet in your development process, including installing Visual Studio, additional components, and NuGet itself.
Preparing Your Workstation
A small set of tools is essential to developing with NuGet. Whether you are a VB.NET or C# developer, whether you develop in Windows Forms, Web Forms, Silverlight, ASP.NET MVC (Model-View-Controller), or for a Windows Phone, you will need Visual Studio or one of the Visual Studio Express editions. You may also need other specific software.
Supported Development Environments
NuGet is supported in the following development environments:
If you do not have access to the Professional, Premium, or Ultimate editions of Visual Studio, you can find some free Visual Studio Express versions at www.microsoft.com/express .
In this book, most examples will use Visual Studio 2012 Ultimate. Keep in mind that the Visual Studio integration is identical across all versions listed in this section, and all versions are equally suited to our purposes. This book will not cover SharpDevelop, but its NuGet integration is similar to that of Visual Studio 2012.
Note If SharpDevelop is your favorite integrated development environment (IDE), don’t throw away this book. SharpDevelop and Visual Studio 2012 share similar ideology and features. SharpDevelop 4.1 includes support for NuGet by default (see http://community.sharpdevelop.net/blogs/mattward/archive/2011/01/23/NuGetSupportInSharpDevelop.aspx ).
Installing the Essential Software
Some examples in this book require you to install specific software. For example, some require the ASP.NET MVC 4 framework. Visual Studio 2012 ships with the ASP.NET MVC 4 framework installed, but you may want to upgrade to the latest version. The easiest way to install these components and configure your development environment is through Microsoft’s Web Platform Installer, or Web PI, as everyone calls it.
The Web PI allows you to select a set of application components and frameworks, install them all at once, and take care of dependencies. For example, if you install the ASP.NET MVC framework, the Web PI will also install .NET 4.5 on your machine. If you wish to have the default configuration for your local development web server installed, the Web PI will both install and configure this for you.
Installing the Web Platform Installer
The Web PI can be downloaded from http://microsoft.com/web . Click the Downloads menu at the top of the page, and then click the Web Platform Installer link, shown in Figure 1-1.
Figure 1-1. The Downloads link to the Web Platform Installer
Once you arrive on the download page, click the large Free Download button, shown in Figure 1-2, to download the Web PI to your computer. Note that Internet Explorer will ask you to run or save the installation file. Click the Run button (also shown in Figure 1-2) to run the Web Platform Installer. Other browsers often have similar options hidden under the Open button, for example.
Figure 1-2. The download page for the Web PI
Installing Components and Configuring Your Environment by Using the Web PI
Once the Web PI is running, you can select a variety of tools, applications, and frameworks to install on your machine from the Web PI main screen, which looks like Figure 1-3. The Web PI also enables you to configure some of the components that are already on your machine.
Figure 1-3. The Web PI main screen
You’ll use the search box at the top-right corner of this screen to find the essential components used in this book. When the Web PI finds a component, simply click the Add button on the right side to add that component to the list of software to install.
Find and add the following components:
After you’ve added these components, click the Install button near the bottom of the Web PI window. This action will display a confirmation dialog box listing the components you’ve selected plus their required dependencies, as shown in Figure 1-4. Click the I Accept button to install all these components.
Figure 1-4. The Web PI confirmation window
Installing NuGet
Since you are reading a book titled Pro NuGet, you can imagine that one of the required components to work your way through this book is NuGet itself. NuGet has a collection of client tools, including the NuGet Visual Studio extension, the NuGet command-line executable, and the NuGet WebMatrix extension. Throughout this book, we’ll mostly be using the Visual Studio extension (both the graphical user interface and the PowerShell console). However, some sections will be using the command-line version of NuGet. This section covers finding and installing these two components.
Throughout this book, we will also use the NuGet Package Explorer (NPE) tool. NPE is not an official Microsoft product; it’s an open source project hosted on CodePlex. NPE is not required for working with NuGet. However, it’s an invaluable tool to have installed for peeking into NuGet packages and seeing how other package authors have done things. It allows you to open, edit, inspect, and validate NuGet packages from an easy-to-use graphical user interface.
Installing the NuGet Visual Studio Extension (Visual Studio 2010)
To get started, navigate to www.nuget.org , the official web site hosting the NuGet tool and a variety of useful NuGet packages to use in your software. Find and click the Install NuGet button. After that, you’ll be taken to the Visual Studio Gallery, where the actual download of the latest version of NuGet is located.
The Visual Studio Gallery displays a purple Download link, as shown in Figure 1-5. Click this link to install the NuGet Package Manager into your Visual Studio environment.
Figure 1-5. The Visual Studio Gallery, where the NuGet Visual Studio extension can be downloaded
Installing the NuGet extension into Visual Studio is very straightforward. The Visual Studio Extension Installer (VSIX) will prompt you to install NuGet into one or more versions of Visual Studio available on your system (Maarten happens to have two of those on his machine, as you can see in Figure 1-6). Click the Install button to register NuGet in Visual Studio.
Figure 1-6. The NuGet installer lists the versions of Visual Studio into which it can be installed
Note NuGet can be installed directly from Visual Studio. In the Tools ä Extension Manager menu, you can search for Visual Studio extensions. Search for NuGet, and click the Install button to install NuGet into Visual Studio.
The Visual Studio Extension Manager is also the place where you can install updates to the NuGet Visual Studio extension. NuGet typically is updated every two to three months. The Updates panel on the Visual Studio Extension Manager will allow you to easily update NuGet to its latest version.
Updating the NuGet Visual Studio Extension (Visual Studio 2012)
Every version of Visual Studio 2012 ships with the NuGet Visual Studio extension installed. Because NuGet is updated every two to three months, chances are the bundled extension has an update available.
To install an update of the NuGet Visual Studio extension, we can use the Tools ä Extensions and Updates menu in Visual Studio. Whenever an updated version of the NuGet Visual Studio extension is available, it will be listed in the dialog box that opens.
The NuGet web site also has a list of all installers available, at http://docs.nuget.org/docs/start-here/installing-nuget . This page also lists the latest nightly builds for NuGet, if you want to work with the very latest bits.
Downloading the NuGet Command-Line Tool
The NuGet command-line tool is used in this book as well. You can download its latest version from http://nuget.codeplex.com . (On this page, you can also download the NuGet source code and even contribute if you want to add a feature to NuGet.)
Select the Downloads menu, as shown in Figure 1-7, and the resulting page will present you with two download options: NuGet Package Explorer and the NuGet.exe Command Line Bootstrapper. Find the NuGet.exe command-line download (make sure not to download the NuGet.exe bootstrapper!). Click its link, accept the license terms, and save NuGet.exe to a location on your hard drive that you can easily find later.
Figure 1-7. The NuGet downloads page on CodePlex
Installing NuGet Package Explorer
Although NuGet Package Explorer (or NPE) is not required to work with NuGet, as we mentioned before, it is handy because it allows you to open, edit, inspect, and validate NuGet packages from an easy-to-use graphical user interface.
NPE is a ClickOnce application that can be installed from inside your browser. To add it to your machine, simply navigate to http://npe.codeplex.com and find the latest download that will install the ClickOnce version of NPE.
Note ClickOnce is a Microsoft technology that allows you to download and run an application from the Internet. Although that concept is not new or special, ClickOnce adds one feature: applications installed through ClickOnce are automatically updated as needed. This means that your NuGet Package Explorer software will always be kept up-to-date automatically.
After installing NPE, you will be greeted by its welcome screen, as shown in Figure 1-8. You can close NPE for now, because we won’t need it again in this chapter. In other chapters, we’ll make extensive use of it, though.
Figure 1-8. The NuGet Package Explorer welcome screen
Downloading Development Builds
If you’re like us and like to experiment with the latest development builds of the NuGet tooling, then the following pointers will be useful to you. The NuGet team uses a publicly accessible TeamCity build server, allowing you to log in as a Guest user and download the build artifacts you want. Note that there’s no guarantee these versions will work as expected, and no support will be given until released. Do not use them in your production environment if you can’t accept the risks.
The following permalinks are always pointing to the latest development builds:
If you require additional information on NuGet, the NuGet command-line executable, or NuGet Package Explorer, the following list of resources may be of help:
Holds downloads for the NuGet Visual Studio extension and NuGet command-line executable (official releases from Microsoft). It also has source code, an issue tracker, and discussion forums available.
Provides the download for NuGet Package Explorer and its source code. It also has an issue tracker and discussion forums available.
The official gallery of public NuGet packages. It lists all available packages, links to documentation, and a download link for the latest official Microsoft release of the NuGet Visual Studio extension.
Contains source code, an issue tracker, and documentation for the software that runs the NuGet Gallery at www.nuget.org .
Contains all continuous integration builds of Outercurve’s NuGet project.
Holds documentation of features, release notes, and several reference pages for specific scenarios.
Blog from the core NuGet team.
Uptime report for www.nuget.org .
NuGet, the NuGet Gallery, and NuGet Package Explorer are open source projects. This means that you can have a look inside to see how a specific feature is implemented, track down bugs, or even add your own contribution to one of these projects. Don’t feel shy: if you have a great idea, either file a feature request or build it by yourself and share it with the world. Who knows? Our next version of the Pro NuGet book may feature something you contributed to NuGet.
Summary
In this chapter, we covered setting up your workstation and all required tools for developing applications using NuGet. NuGet comes bundled with recent editions of Visual Studio, so apart from updating the NuGet Visual Studio extension, that is all there is to it. You have also seen how to install the NuGet Visual Studio extension with older Visual Studio versions.
There are several other tools you may want to have installed on your system when working with NuGet, such as the command-line tool and NuGet Package Explorer.
We’ve ended this chapter with a list of resources related to NuGet that offer valuable additional information. This list also contains links to the project sites behind NuGet, where you can contribute to the documentation or the actual code of NuGet; it’s all open source!
In the next chapter, we’ll show you how to consume your first NuGet package.
3.145.70.38