Maarten Balliauw
and
Xavier Decoster
Pro
NuGet
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
This book was purchased by c2748214@drdrb.com
v
Contents at a Glance
About the Authors ������������������������������������������������������������������������������������������������������������� xvii
About the Technical Reviewers ����������������������������������������������������������������������������������������� xix
Foreword ��������������������������������������������������������������������������������������������������������������������������� xxi
The Bigger Picture ����������������������������������������������������������������������������������������������������������� xxiii
Chapter 1: Getting Started ■ �������������������������������������������������������������������������������������������������1
Chapter 2: Consuming and Managing Packages in a Solution ■ ����������������������������������������13
Chapter 3: Authoring Packages ■ ���������������������������������������������������������������������������������������47
Chapter 4: Publishing Packages ■ ��������������������������������������������������������������������������������������99
Chapter 5: Hosting Your Own NuGet Server ■ ������������������������������������������������������������������117
Chapter 6: Continuous Package Integration ■ ������������������������������������������������������������������159
Chapter 7: Automated Delivery ■ ��������������������������������������������������������������������������������������179
Chapter 8: NuGet Recipes ■ ����������������������������������������������������������������������������������������������215
Chapter 9: Extending NuGet ■ �������������������������������������������������������������������������������������������259
Chapter 10: NuGet as a Protocol ■ ������������������������������������������������������������������������������������287
Appendix A: Package Manifest Reference ■ ���������������������������������������������������������������������309
Appendix B: NuGet Command-Line Reference ■ ���������������������������������������������������������������321
Appendix C: NuGet Package Manager Console PowerShell Reference ■ ��������������������������331
Appendix D: NuGet Configuration File Reference ■ �����������������������������������������������������������339
Index ���������������������������������������������������������������������������������������������������������������������������������347
1
Chapter 1
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:
Visual Studio 2013 (all editions)•
Visual Studio 2012 (all editions)•
Visual Studio 2010 (all editions)•
Visual Web Developer 2010 Express•
WebMatrix 3•
WebMatrix 2•
SharpDevelop•
CHAPTER 1 ■ GETTING STARTED
2
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. SharpDe-
velop 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.