How to Install Nuget Package in C#?
In this tutorial, we will be seeing how to install NuGet packages in C#. NuGet is the official package-manager for .NET. Packages are basically compiled libraries with some descriptive metadata. NuGet is an important tool for any modern development platform through which developers can create, share, and consume useful code. NuGet packages can also be defined as “re-usable and pre-defined pieces of code which benefit other developers as well”.
Prerequisites: Visual Studio, Stable Internet, C#
Downloading and Installation of Nuget package in C#
Follow the further steps to install Nuget Package in C#
Step 1: Creating or Opening an existing project
NuGet packets are installed in projects and hence we first need to create a project or open an existing one.
In this particular tutorial, we will be creating a MVC project. Here we are using Visual Studio 2019 and naming the project as NugetDemo.
Click on create a new project and choose ASP.NET Web Application(.NET Framework) and click next.
Step 2: Then we name the project. Here it is named as NugetDemo and click Create.
Step 3: Next click MVC and click on the create button.
After following the above steps, the project has been created and we shall now see the NuGet Package Installation. We are going to be installing the Bootstrap package. For more details on Bootstrap click here.
There are multiple approaches to do so.
Approach 1: Using Packet manager console to install Bootstrap package
Step 4: Go to Tools->NuGet Package Manager->Packet Manager Console
Step 5: Installing via commands
The general command syntax: Install-Package <package_name>
For Bootstrap the command will be: Install-Package bootstrap
Once installed you will get the following screen.
Note: You can even specify the version name however by default it is the latest one like in case of bootstrap it is 5.2.2.
For Bootstrap the command with the version specified will be: Install-Package bootstrap -Version 5.2.2
Once installed, you will get the following acknowledgment.
Approach 2: Using Manage packages for solution to install Bootstrap package
Step 4: Go to Tools->NuGet Package Manager->Manage NuGet Packages for Solution…
The below screen will appear and now search for the required package in Browse, and choose the version(optional).
Step 5: Click install on the bottom right corner.
After clicking install wait for a few seconds and you shall get a confirmation as follows:
Note: In order to install or uninstall NuGet packages make sure your project is not running. If it is, stop running, install or uninstall and then build the project and run.
Please Login to comment...