Adding Packages to the Project ASP Help

As I explained earlier in the chapter, I prefer to create a basic Visual Studio project and then explicitly add the features I need. This is less work than you might expect because Visual Studio supports NuGet, which is a package manager that provides access to a wide catalog of packages for .NET application development. The integration into Visual Studio allows for the automatic downloading, installation, and dependency management of packages and has transformed the process of using standard libraries in .NET development.

The NuGet package catalog. which you can browse at www.asphelponline.com is extensive and includes many popular open source web application packages. Microsoft has given tacit support to some of these packages by including them in the Visual Studio templates for new ASP.NET projects, but you can use NuGet directly to install these packages without getting the rest of the (generally useless) template content. One package that Microsoft has adopted with tile MVC 5 release is Bootstrap, which is an excellent CSS and JavaScript library for styling HTML that grew out of a project at Twitter. I have absolutely no design skills at all, and I like using Bootstrap because it lets me style content during the early stages of development without making too much of a mess. I like to work with professional designers on real projects (and i recommend you do the same), but in this book I’ll use Bootstrap to make some the examples easier to understand and to highlight specific results and features.

Note Bootstrap is only one of the packages that Microsoft has adopted, and I only briefly describe its use in this chapter. For full details of client-side development for MVC framework projects, see my Pro ASP.NET MVC 5 Client Development book, which is published by A press.

I’ll show you how I use Bootstrap later in this chapter, but ill this section I will show you how to use the Visual Studio support for NuGet to download and install tile Bootstrap package.

Note Bootstrap isn’t directly related to the MVC Framework or the ASP.NET platform. In this chapter I use it to demonstrate how to install a NuGet package and in later chapters to make the examples easier to follow. If you are familiar with NuGet and Bootstrap (or are not interested in either), then you can move directly to Part 2 of this book, where I turn to the details of the ASP.NET platform.

Visual Studio provides a graphical interface that lets you navigate through the package catalog, but I prefer to use the console feature that accepts NuGet commands directly in Visual Studio. Open the console by selecting Package Manager Console from the Tools → Library Package Manager menu and enter the following command:

Install-Package -version 3.0.3 bootstrap

The Install-Package command instructs Visual Studio to add a new package to the project. When you press the Enter key, Visual Studio will download and install the Bootstrap package and any other packages that it depends on. Bootstrap depends only on the popular jQuery library, which Visual Studio added automatically when setting up the project, along with some additional JavaScript files that use jQuery to handle form validation.

Tip The -version argument allows me to specify a particular version of the package, and version 3.0.3 is the current version of Bootstrap available as I write this. The latest version of the package will be installed if you omit the -version argument when using the Install-Package command. I use specific versions of packages in this book to ensure that you are able to re-create the examples.

The Bootstrap NuGet package adds some CSS files to the Content folder (which is the home of static content in an MVC framework application) and some JavaScript files to the Scripts folder. Bootstrap mainly works through CSS files, but there are some java Script enhancements for more complex interactions. (The Bootstrap package also creates a fonts folder. Not all open source libraries fit neatly into the ASP.NET project structure, so occasionally you will see artifacts like this to support assumptions made by the library about the layout of its files.)