更改NuGet包位置文件夹

时间:2017-12-17 22:48:43

标签: visual-studio nuget nuget-package nuget-package-restore

我想更改NuGet包文件夹,但它不会更改它。 我所做的是创建文件nuget.config

<configuration>
    <config>
        <add key="repositoryPath" value="C:\projects\" />
    </config>
</configuration>

我将此文件添加到解决方案文件夹(位于.sln文件的同一文件夹中)或项目文件夹中,然后重新启动VS,但没有任何反应。 我正在使用Visual Studio 2017 Community

2 个答案:

答案 0 :(得分:11)

Change NuGet package location folder

Depending on what sort of project you are using this setting may or may not be successfully to change NuGet packager folder.

If you are using a .NET Framework project that has a packages.config file then this setting will change the nuget package folder to C:\projects\.

But if you are using a project.json file, then this setting will not successful. Because project.json project doesn't support repositoryPath config.

To change the nuget packager folder, you can you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "c:\teampackages". Or you can place a NuGet.Config file next to the solution with the following content:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <config>
      <add key="globalPackagesFolder" value=".\packages" />
    </config>
</configuration>

For the detail info, you can refer to this thread:

Dotnet restore does not honour nuget.config 'repositoryPath'.

Update:

I noticed that you are creating Xamarin.Forms project with Visual Studio Community 2017, the reference should be PackageReference, for this sort of project, you should use add below code to the .csproj file:

<PropertyGroup>
  <RestorePackagesPath>D:\Test\packages</RestorePackagesPath>
</PropertyGroup>

Then restart Visual Studio, VS/NuGet will restore nuget packages to the D:\Test\packages, it works fine on my side, you can check my test sample:

enter image description here

Hope this helps.

答案 1 :(得分:-1)

在工具/ Nuget包管理器/包管理器设置中 Options