文章目录
前言
由于C盘的空间有限,NuGet的包位置默认又在C盘,这就很烦,只能去自己手动修改
NuGet 配置文件位置
配置文件共有三处,添加下面的内容即可 (高版本可以设置环境变量解决)
<-- 添加下面的键值即可 -->
<config>
<add key="globalPackagesFolder" value="E:\nuget" />
</config>
C:\Users\NueXini\AppData\Roaming\NuGet\NuGet.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<config>
<add key="globalPackagesFolder" value="E:\nuget" />
</config>
</configuration>
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\"/>
</packageSources>
<config>
<add key="globalPackagesFolder" value="E:\nuget" />
</config>
</configuration>
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
<?xml version="1.0" encoding="utf-8"?>
<!--<auto-generated>
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
</autogenerated>-->
<configuration>
<fallbackPackageFolders>
<add key="Microsoft Visual Studio Fallback Folder" value="D:\Microsoft Visual Studio\2019\Shared\NuGetPackages" />
</fallbackPackageFolders>
<config>
<add key="globalPackagesFolder" value="E:\nuget" />
</config>
</configuration>
NuGet 环境变量
使用
NUGET_PACKAGES
环境变量代替
globalPackagesFolder
或
repositoryPath
使用
NUGET_HTTP_CACHE_PATH
环境变量替代
http-cache
使用
NUGET_PLUGINS_CACHE_PATH
环境变量替代
plugins-cache
查看所有文件夹位置
dotnet nuget locals all --list
清除所有缓存
dotnet nuget locals all --clear
其他问题
-
如果你不知道你的默认配置文件在哪里,请查阅
https://learn.microsoft.com/zh-cn/nuget/consume-packages/configuring-nuget-behavior
-
还能配置更多参数,请查阅
https://learn.microsoft.com/zh-cn/nuget/reference/nuget-config-file
-
如果不想修改设置,可以设置环境变量
https://learn.microsoft.com/zh-cn/nuget/consume-packages/managing-the-global-packages-and-cache-folders
-
NuGet命令行用法 (cmd/powershell 输入
dotnet nuget
)
https://learn.microsoft.com/zh-cn/nuget/reference/nuget-exe-cli-reference