[NuGet 2.7] New package restore doesn't work on Mono when using SLN file


The new package restore workflow doesn't work on Mono when using an SLN file, i.e. invoking
nuget.exe -restore MySolution.sln

returns: "An exception was thrown by the type initializer for NuGet.Common.Solution"

After digging into the source code (specifically Solution.cs), it turns out that NuGet uses an internal MSBuild class for parsing SLN files, Microsoft.Build.Construction.SolutionParser, which is not available on Mono.

It appears that NuGet only needs to parse the SLN to find paths to project-level packages.config files, which IMHO shouldn't require relying on invoking an internal class via reflection.

Restoring packages by specifying the packages.config file works fine on Mono.

Ubuntu Server 12.10
Mono 3.1
NuGet 2.7RC
Closed Aug 26, 2013 at 7:27 PM by deepakverma


akoeplinger wrote Aug 20, 2013 at 11:43 PM

I've spent some time on this and got it working on Mono by parsing the relevant pieces of the SLN myself via a Regex:

Is this something that could be considered for a PR ?

dfowler wrote Aug 23, 2013 at 5:59 AM

This code needs tons of unit tests but it would be great to not have that dependency

dotnetjunky wrote Aug 23, 2013 at 6:21 AM

we won't use this code. We have a different solution.

feiling wrote Aug 23, 2013 at 8:27 PM

Fixed. The fix is to use XBuild's solution parser when nuget.exe is running on Mono. See http://nuget.codeplex.com/SourceControl/changeset/c731af8535196a808b559e479d76fa1bcce41030

akoeplinger wrote Aug 23, 2013 at 9:24 PM

Great, that's a much better solution, thanks!