My company has NuGet package reference trouble due to our use of Multi-Homed Projects:
It's pretty common to include a project in mutliple solutions. Unfortunately, NuGet cannot understand when this is the case. And because NuGet uses a packages folder at the solution level, the Hint Paths in projects become relative to the solution. If there are multiple solutions using a project, these relative paths can easily break.
I'm trying to figure out a reasonable way to keep the Hint Paths from breaking.
One idea I had was to use an environment variable to point to a shared package folder (similar to how NuGet does it with .NET Core projects).
I've tried to create a nuget.config
like the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="%USERPROFILE%\.nuget\shared_packages" />
</config>
</configuration>
And when I install a package it generates a Hint Path with a relative path:
<Reference Include="QRCoder, Version=1.3.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\..\..\Users\Username\.nuget\shared_packages\QRCoder.1.3.5\lib\net40\QRCoder.dll</HintPath>
</Reference>
This won't work on other machines so I have to manually edit the .csproj
file to something like this:
<Reference Include="QRCoder, Version=1.3.5.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>$(USERPROFILE)\.nuget\shared_packages\QRCoder.1.3.5\lib\net40\QRCoder.dll</HintPath>
</Reference>
Can I configure nuget.config
(or something else?) to make the Hint Path use the literal value of $(USERPROFILE)\.nuget\shared_packages
so I don't have to manually edit the .csproj
file every time?