1

Closed

Cannot restore packages relative to $(SolutionDir) when using command line

description

I wanted to establish a link between two projects via my local file system by using packages instead of a direct reference. I added an item to my project like so (which is where my .nupkg files are output to):
<PackageSource Include="$(SolutionDir)bin">
  <Visible>False</Visible>
</PackageSource>
And this works when building from VS but not from the command line. The reason appears to be because the $(SolutionDir) default at the top of the default NuGet.targets page gives a relative address and if you have a @(PackageSource) which isn't a web url but is relative to the solution you get a relative path. This causes an error in nuget.exe.

The easiest solution I could come up with was to change the flattening of @(PackageSource) to $(PackageSources) from this:
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
to:
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource->'%(FullPath)')</PackageSources>
For uri's the FullPath metadata returns the same result, for local files the paths are resolved to fullpaths, which nuget.exe can work with. This works.
Closed Jun 30 at 4:48 PM by danliu
close per customer comments.

comments

justinc wrote Jun 28 at 4:02 PM

Actually, I am mistaken. The problem remains, I do not know how to reference both the nuget uri's and a relative file path and have it not produce an error in nuget.exe :(

justinc wrote Jun 28 at 4:09 PM

Ok nevermind, I believe this is just me failing at msbuild. The solution is to add this to your NuGet.targets file:
<PackageSource Include="$([System.IO.Path]::GetFullPath($(SolutionDir)))bin" />
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
Which gives you the full path during restore like:
"..\..\.nuget\NuGet.exe" install "C:\Users\justin\projects\codeplex\metasharp\src\MetaSharp.Transformation.Tests\packages.config" -source "C:\Users\justin\projects\bin;https://www.nuget.org/api/v2/;https://my-nuget-source/nuget/"  -NonInteractive  -solutionDir "..\..\ "
And then it's all good. I believe you can close this issue.

justinc wrote Jun 28 at 4:10 PM

Or for bonus points you could make it resolve relative paths for the source uri's :)