Skip to main content
Mark Ku's Blog

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.

  1. package.config setting
<package id="Albireo.Base32" version="1.0.1.0" allowedVersions="[1.0.1.0]" targetFramework="net461" />
  1. 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"allowedVersions="[1" allowedVersions="[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

Author

Mark Ku

10 年以上的軟體工程師,做過北美電商與 AI SaaS 訂閱收費系統。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··651

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··461

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··282

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··216

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11
Mark Ku
··213

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··212

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning