Common NuGet CLI Commands
Automated NuGet updates
Restore NuGet packages for the current project
nuget restore Build.sln
Run NuGet update
Download nuget.exe from the NuGet website and specify the MSBuild path.
VS 2017
nuget update .\Test\Test.AP.Site.Test.csproj -msbuildpath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin" -Source
VS 2019
nuget update .\Test\Test.AP.Site.Test.csproj -msbuildpath "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin" -Source
Restrict NuGet update versions
Edit package.config and add allowedVersions; this attribute prevents certain assemblies from being force-updated.
- package.config setting
<package id="Albireo.Base32" version="1.0.1.0" allowedVersions="[1.0.1.0]" targetFramework="net461" />
- What allowedVersions means
5.2 means ≥ 5.2
(,8.2] means ≤ 8.2
(7.3,) means > 7.2
(,6.5) means < 6.5
Use [] to specify an exact version
P.S. If you need to change many packages at once, you can use a regex to do a bulk replace:
version="([^"]*)"
with
version="1]"
NuGet sources
nuget source
nuget sources Add -Name "MyServer" -Source \\myserver\packages
nuget sources Disable -Name "MyServer"
nuget sources Enable -Name "nuget.org"
Clear the local NuGet cache
nuget locals list
nuget locals all -clear





























Comments