This project is read-only.


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


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">
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>
<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, 2014 at 5:48 PM by danliu
close per customer comments.


justinc wrote Jun 28, 2014 at 5: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, 2014 at 5: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="" />
<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://my-nuget-source/nuget/"  -NonInteractive  -solutionDir "..\..\ "
And then it's all good. I believe you can close this issue.

justinc wrote Jun 28, 2014 at 5:10 PM

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