1

I have cloned a git repository containing a VS project referencing Json.Net as a NuGet package. This reference appears in the form:

<HintPath>..\..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>

I have the repository cloned (along with all my other git repositories) to D:\Repos.

As you can see, there is no possible way I can have my packages installed 3 directories above this.

Using an environment variable (NUGET_PACKAGES) or a packages.config file doesn't appear to override the relative paths that get hard-baked into project files on package installation.

While this exact instance could be solved by burying this particular repo 3 folders deeper in the file system, this is not a solution to the problem.

Is it possible to tell Visual Studio to ignore these author-specified HintPaths in favor of a user-specified path of some sort?

Pang
  • 9,564
  • 146
  • 81
  • 122
Alex McMillan
  • 17,096
  • 12
  • 55
  • 88

1 Answers1

1

You cannot disable the hint paths when adding NuGet packages if you are using a packages.config file.

I would look at using a NuGet.Config file next to the solution and use the repositoryPath setting to define where you want the packages to be.

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

Another option would be to use a project.json file, although this file will be disappearing at some point. Using a project.json file means that you do not have any hint paths stored in your .csproj file at all. The assemblies are resolved at build time.

Pang
  • 9,564
  • 146
  • 81
  • 122
Matt Ward
  • 47,057
  • 5
  • 93
  • 94
  • It's not my repository, so I can't modify it like that. One would think having my own local copy of a config with a `repositoryPath` field would override the HintPaths, but no... apparently that would be too convenient. It seems the whole system was designed to fight open source software or something. – Alex McMillan Aug 18 '16 at 20:41
  • You can put the NuGet.Config file at a directory outside the repository. NuGet will go up the directory tree until it finds a NuGet.Config file. However if you cannot modify the .csproj files, if they are in a different repository, I am not sure you can do anything. They will always refer to the other packages directory. – Matt Ward Aug 18 '16 at 22:11
  • So there is no solution? This is simply outside the bounds of the capabilities of nuget or Visual Studio solutions in general? – Alex McMillan Aug 18 '16 at 23:07
  • The solution is to use the NuGet.Config file to fix the hint paths. Or just restore the packages for the solution in the other repository so it builds without having to change the hint paths. The second option is the better approach for source code you have no control over. Or finally you can try specifying a [reference path](http://stackoverflow.com/questions/1882038/hintpath-vs-referencepath-in-visual-studio) which I believe will take precedence over a hint path. – Matt Ward Aug 19 '16 at 08:57