Installing the NuGet Packages By Package Manager Console in Web API

Introduction

This article describes how to find, install, remove and update the NuGet Packages using the Commands Web API. For Commands we use the Package Manager Console. In the Web API we use a different package and need to install it in the application. Now we will explain the process of package installation.

  1. Finding the Package.
  2. Install The package.
  3. Remove The Package.
  4. Update The Package.

Find The Package:

For finding the package, first we need to open the Package Manager Console. We can open it as in the following:

  • From the Tools menu.
  • Select "Library Package Manager".
  • Then select "Package Manager Console".

Select Console Package Manager.jpg

The Package Manager Console window looks like this:

Package  Manage Console Window

Now you enter the Command in the Packager Manager Console window for finding all the packages available in the selected package source. We use the "Get-Package -ListAvailable" command.

Find list of Available package

Install the Package

For installing the package we need to know the package name and enter the command "Install-Package Packagename" in the Package Manager Console and press Enter. Here we install the Package "Elmah" so we type the command "Install-Package elmah " and press Enter. After installing this package it will be display as:

Install Package

Now we check the "References" folder in the "Solution Explorer" in which it added the library of the "elmah" as libraries.

Now see the "Web.Config" file that applied some changes.The following image shows the changes:

Config file

Your application folder has a "packages" folder in which you can see the "elmah" package folder.

Package folder

The "Packages" folder has a sub-folder of the installed package. This folder has all the files that are installed by the package.

Elmah Package

Remove The Package

If you need to remove any package then that is possible. First you select the Package Manager Console. Go to "Tools", select "Library Package Manager", then select "Package Manager Console". If you do not know which package name you want to remove then just type the "Get-Package" command that will fetch all packages that are currently installed.

Find the Package

After finding the package that you want to remove then type the "Uninstall-Package elmah" command. This command will successfully remove the specified package.

Remove Package

Updating the Package

Go to the "Tools" menu, then select "Library Package Manager" and then select "Package Manager Console". For finding the update version of the package enter the command "Get -Package Updates", it will then display all the updatable packages.

Find Updating Package

Just see the example for updating the package. Here you will see the update of the jQuery package. We use the "Update-Package jQuery" command and the jQuery package will successfully update and it remove the oldest version of the jQuery.

Update Package

Up Next
    Ebook Download
    View all
    Learn
    View all