Monday, 12 January 2015

NuGet Package Manager – part 1

NuGet Package Manager is an extension for Visual Studio that simplifies installing third party libraries for a project. [link]

NuGet Package Manager downloads a package containing the third party library and configures the project to use the library.

Normally you would have to download and extract the library, configure the project to find the Include and Lib directories of library and add the library’s *.lib file or files to the project’s dependencies in the project’s Property Pages.

To install NuGet Package Manager, run Visual Studio while connected to the internet.
Go to TOOLS>Extensions and Updates….

Click Extensions and Updates...

Expand the Online section and click Visual Studio Gallery and Visual Studio will retrieve information about available extensions.

See what extensions are available online

Find and select NuGet and click on the “Download” button. Use search if need be.

Download NuGet

Install NuGet. The UAC allow changes dialog may appear before the following dialog.

Install NuGet

Installation complete

You must restart Visual Studio to use the NuGet Package Manager extension.

Restart Visual Studio

Access Nuget Package Manager from the TOOLS menu.

NuGet Package Manager added to TOOLS menu

To find out if a third party library is available, search for the library at the NuGet site.

Search for a package at nuget.org

The webpage for the package will contain a command which is used to install the package into a project.

Get the command to install

To install a package into a project open the solution/project in Visual Studio and go to TOOLS>NuGet Package Manager>Package Manager Console.

Start the Package Manager Console

This will open the Package Manager Console.

The Package Manager Console

At the prompt, “PM>” type the install command for the package followed by –ProjectName, followed by a space and your project name and press the “Enter” key. If your project is the StartUp project which is displayed in Bold in the Solution Explorer you do not have to specify a project name.
You must be connected to the internet to download a package.

The reference for the console commands can be found here. [link]

Enter the command to install

NuGet installs the WTL package. Note you also get an option to install the WTL App Wizard into Visual Studio.

WTL is installed

There is another way to install a package with NuGet.

Right click on the project in Solution Explorer and click Manage NuGet Packages….

Go to Manage NuGet Packages...

A list of available packages will be retrieved from nuget.org.

A list of available packages will be retrieved

Search for the package you want and click install.

Search for your package and install

The package is installed

The third party libraries installed with NuGet are located in a folder named “packages” located in the solutions folder or if there is no solution, inside the project’s folder.

Packages downloaded to packages folder


next

No comments:

Post a Comment