Is it possible to change the location of packages for NuGet?

前端 未结 15 1819
误落风尘
误落风尘 2020-11-22 17:11

I have the following convention for most of my projects:

/src
    /Solution.sln
    /SolutionFolder
        /Project1
        /Project2
        /etc..
/lib
          


        
相关标签:
15条回答
  • 2020-11-22 17:20

    A solution for Nuget 3.2 on Visual Studio 2015 is:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <config>
            <add key="repositoryPath" value="../lib" />
        </config>
    </configuration>
    

    Using forward slash for parent folder. Save above file (nuget.config) in solution folder.

    Reference is available here

    0 讨论(0)
  • 2020-11-22 17:20

    One more little tidbit that I just discovered. (This may be so basic that some haven't mentioned it, but it was important for my solution.) The "packages" folder ends up in the same folder as your .sln file.

    We moved our .sln file and then fixed all of the paths inside to find the various projects and voila! Our packages folder ended up where we wanted it.

    0 讨论(0)
  • 2020-11-22 17:22

    In order to change the path for projects using PackageReference instead of packages.config you need to use globalPackagesFolder

    From https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file

    globalPackagesFolder (projects using PackageReference only)

    The location of the default global packages folder. The default is %userprofile%.nuget\packages (Windows) or ~/.nuget/packages (Mac/Linux). A relative path can be used in project-specific nuget.config files. This setting is overridden by the NUGET_PACKAGES environment variable, which takes precedence.

    repositoryPath (packages.config only)

    The location in which to install NuGet packages instead of the default $(Solutiondir)/packages folder. A relative path can be used in project-specific nuget.config files. This setting is overridden by the NUGET_PACKAGES environment variable, which takes precedence.

    <config>
        <add key="globalPackagesFolder" value="c:\packageReferences" />
        <add key="repositoryPath" value="c:\packagesConfig" />
    </config>
    

    I put Nuget.config next to my solution file and it worked.

    0 讨论(0)
  • 2020-11-22 17:24
    1. Created a file called "nuget.config".
    2. Added that file to my solutions folder

    this did NOT work for me:

    <configuration>
      <config>
        <add key="repositoryPath" value="..\ExtLibs\Packages" />
      </config>
      ... 
    </configuration>
    

    this did WORK for me:

    <?xml version="1.0" encoding="utf-8"?>
    <settings>
      <repositoryPath>..\ExtLibs\Packages</repositoryPath>
    </settings>
    
    0 讨论(0)
  • 2020-11-22 17:29

    Okay for the sake of anyone else reading this post - here is what I understand of the myriad of answers above:

    1. The nuget.config file in the .nuget folder is relative to that folder. This is important because if your new folder is something like '../Packages' that will put it where it always goes out of the box. As @bruce14 states you must do '../../Packages' instead

    2. I could not get the latest nuget (2.8.5) to find a packages folder outside of the standard location without enabling package restore. So once you enable package restore then the following should be added to the nuget.config file inside of the .nuget folder to change the location:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        ...
        <config>
          <add key="repositoryPath" value="..\..\Packages" />
        </config>
        ...
      </configuration>
      
    3. (This is important) If you make ANY changes to the package folder location inside of the nuget.config files you must restart visual studio or close/reload the solution for the changes to take effect

    0 讨论(0)
  • 2020-11-22 17:31
    1. Create nuget.config in same directory where your solution file is, with following content:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <config>
        <add key="repositoryPath" value="packages" />
      </config>
    </configuration>
    

    'packages' will be the folder where all packages will be restored.

    1. Close Visual studio solution and open it again.
    0 讨论(0)
提交回复
热议问题