dotnet CLI – how to update a NuGet package and add a new NuGet package
Adding and updating NuGet packages via command line – dotnet CLI
Just like we can add, remove and update NuGet packages via UI in Visual Studio or Visual Studio Code we can accomplish the same using the dotnet CLI.
Adding package
For example, to add ASP.NET Core CORS package we run the following:
dotnet add package Microsoft.AspNetCore.Mvc.Cors
Adding package from specific source/feed
However, if we wanna use another NuGet source like MyGet and lets say we wanna install SignalR we do this:
dotnet add package Microsoft.AspNetCore.SignalR -s https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json
Update package
How do we update a package? We install a specific version of the package.
To install a specific version SignalR from same ASP.NET Core CI dev source:
dotnet add package Microsoft.AspNetCore.SignalR -s https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json -v 1.0.0-preview3-26035
Remove package
dotnet-remove package Microsoft.AspNetCore.SignalR
Adding source to NuGet
Adding a source to NuGet:
nuget sources Add -Name "ASP.NET Core CI dev" -Source https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json
You could also manually add sources by changing NuGet.Config file
- Mac ~/.config/NuGet/NuGet.Config
- Windows %AppData%\NuGet\NuGet.Config
- Linux ~/.config/NuGet/NuGet.Config