Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set a relative path for a file-based package source with NuGet?

Tags:

nuget

I'm using NuGet 2.1 with multiple solutions, each in a child directory under a single parent directory and a single packages directory which is shared by all the solutions (this became possible with NuGet 2.1).

I'd like to add a file-based package source which points to the packages directory in my working copy (I'm using Subversion).

This works:

<configuration>
  <repositoryPath>_Packages</repositoryPath>
  <activePackageSource>
    <add key="Working copy package source" value="C:\AllMySolutions\_Packages" />
  </activePackageSource>
</configuration>

This doesn't:

<configuration>
  <repositoryPath>_Packages</repositoryPath>
  <activePackageSource>
    <add key="Working copy package source" value="_Packages" />
  </activePackageSource>
</configuration>

I don't want to hard-code the absolute path but can't find a way of using a relative path in the value attribute inside activePackageSource.

like image 957
Tom Robinson Avatar asked Oct 17 '12 11:10

Tom Robinson


People also ask

How do I change the default location of a NuGet package?

Open %AppData%\NuGet folder, open existing NuGet. Config file. Edit repositoryPath key and set new destination.

Where are NuGet package sources stored?

The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux). A relative path can be used in project-specific nuget.


Video Answer


3 Answers

It looks like this is now supported.

http://nuget.codeplex.com/workitem/2810

  1. Put a file called nuget.config in the root of your solution (next to packages folder and solution file) containing:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <add key="Local" value="packages-local" />
      </packageSources>
    </configuration>
    
  2. Build you packages to the packages-local folder.

  3. The packages in this folder will be available to add to other projects in the solution. (You may need to restart VS or at least close-reopen your solution for the config to be picked up).

like image 132
Matthew Winder Avatar answered Sep 30 '22 09:09

Matthew Winder


I had same problem with <repositoryPath>. I needed to force all SOLUTIONs in my git repository to use same folder to store their NuGet packages. So I created a nuget.config file on the root of the repository with the following contents, as it was described in documentations:

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

After manually creating NugetPackages beside nuget.config and installing packages, there was nothing in that directory, but everything was working fine. Then I found that VS has created C:\NugetPackages and moved packages there. After trial and error for a while, at last the relative path using .\ worked for me:

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

I hope it behaves the same for other configurations as well.

P.S.: As Matthew already said, I had to restart VS to make my edits in nuget.config take effect.

like image 44
saastn Avatar answered Sep 26 '22 09:09

saastn


For .NETCore/.NET5 and newer, the config key repositoryPath doesn't work anymore, and it is now named globalPackagesFolder, so:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>
        <add key="globalPackagesFolder" value=".\packages\" />
    </config>
</configuration>
like image 32
knocte Avatar answered Sep 29 '22 09:09

knocte