nugetsln-file

nuget restore: Exception has been thrown by the target of an invocation


When I run nuget restore from the command line, I get

Error parsing solution file at MyProject.sln: Exception has been thrown by the target of an invocation.

but restoring nuget packages from Visual Studio runs without errors. Any workarounds?


Solution

  • This error is particularly frustrating on large solutions with many projects, as there is no hint from NuGet at what point in the file parsing failed.

    To analyze the problem, try msbuild MyProject.sln; the parser of msbuild is slightly more verbose. At least it will give you a line number, so you will know where to look for the error. Open MyProject.sln in a text editor to inspect that line. In my case, it was simply a blank line that accidentally got introduced while manually resolving a TFS merge conflict.

    (It may seem quite obvious to call msbuild, but in our case, that call was part of a larger build script where nuget restore would come first, aborting the build process before msbuild was reached.)

    A future release of NuGet should return a more detailed error message; see issue #1150.