简体   繁体   English

NuGet 3.5 / Visual Studio 2015-更改程序包缓存位置

[英]NuGet 3.5 / Visual Studio 2015 - Change package cache location

Is it possible to change the nuget package cache path from %UserProfile%\\.nuget\\packages to a custom location? 是否可以将nuget包缓存路径从%UserProfile%\\.nuget\\packages更改为自定义位置?

I tried using the environment variable NuGetCachePath, but it doesn't seem to work with it. 我尝试使用环境变量NuGetCachePath,但似乎无法使用它。

You can modify the location of the package cache by setting an environment variable named NUGET_PACKAGES . 您可以通过设置一个名为NUGET_PACKAGES的环境变量来修改程序包缓存的位置。

For example, change your location from C:\\Users\\Frank\\.nuget\\packages to F:\\Users\\Frank\\.nuget\\packages by setting the latter value to a "system" environment variable named NUGET_PACKAGES , and rebooting. 例如,通过将后者的值设置为名为NUGET_PACKAGES的“系统”环境变量,然后重新启动,将位置从C:\\Users\\Frank\\.nuget\\packages更改为F:\\Users\\Frank\\.nuget\\packages

Reference: https://github.com/NuGet/Home/issues/1905 参考: https : //github.com/NuGet/Home/issues/1905

No, there is no way to change this for now. 不,暂时没有办法更改。 The "NuGetCachePath" environment variable you mentioned is for a modified version to work with MonoDevelop on Linux: mrward/nuget . 您提到的“ NuGetCachePath”环境变量是用于在Linux上与MonoDevelop一起使用的修改版本: mrward / nuget

I found a setting which should do the trick, the config file that is required to be modified is %APPDATA%\\NuGet\\NuGet.Config ( Config File Documentation ). 我找到了可以解决问题的设置,需要修改的配置文件为%APPDATA%\\NuGet\\NuGet.Config配置文件文档 )。

But there seems to be a catch, as changing the repositoryPath also means that the HintPath of the .csproj is no longer correct (at least for non .net core projects). 但是似乎存在一个问题,因为更改repositoryPath也意味着.csproj的HintPath不再正确(至少对于非.net核心项目而言)。 And as the .csproj most likely is added to version control this is really a big problem. 并且由于.csproj最有可能被添加到版本控制中,这确实是一个大问题。

Here is the setting required to change/add to the file: 这是更改/添加到文件所需的设置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>
        <add key="repositoryPath" value="D:\Cache\NuGet2\packages" />
    </config>
    <!-- More settings follow -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM