Nuget is a package manager for .NET applications.It is used to include third party assemblies in our solution.Installing and configuring third party components may be a time consuming task and can take significant effort.Whenever we need to consume any external library in our application then we need to repeat few steps such as:
- Downloading the assembly
- Adding the assembly references to the solution
- Adding any other resources required by the assembly such as script files
- Modifying the configuration files such as web.config as required by the library
- Downloading and adding references to other dependent assemblies
NuGet is a open source package manager using which we can manage the external application dependencies.Nuget automates all of the above mentioned steps so we just need to tell which packages we need for our application.
We can access Nuget through either through console or through GUI dialog
Package manager console
We can manage the NuGet packages using the PowerShell commands in the package manager console.The package manager console can be accessed through the Tools–>Library Package Manager option.
On selecting the Package Manager Console option from the tools menu a PowerShell Console is displayed:
Some of the useful commands we can use in the PowerShell console are
For installing package and any dependencies
For uninstalling package
Displays all the powershell commands which can be used in this console
Updates a package and its dependencies to latest version
Package Manager Dialog
We can also manage the nuget packages using this GUI based option.
On selecting the Manage NuGet packages option from the references node a dialog for managing the NuGet packages is displayed.In this dialog we can search and install the required NuGet packages
We can also access this GUI using the Tools–>Library Package Manager option.
On selecting this option the following dialog is displayed:
We can search the required packages and install them using the above dialog.The packages are fetched from a central feed location.The packages are published to this central feed location by the package developers.
We can use the “nuget restore YourSolution.sln” command to restore the packages for the solution.If we have the NuGet2.7 or above version then visual studio automatically restores the missing nuget packages when compiling the solution.
To update all the packages used in the solution to the latest versions we use the following command in the PowerShell console
So as we have seen NuGet automatically manages the references to assemblies which significantly reduces the effort in configuring references to third party assemblies.
Leave a Reply