Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 214
sashoalm Avatar asked Jul 14 '17 10:07

sashoalm


2 Answers

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.

like image 125
Ruud Helderman Avatar answered Sep 17 '22 05:09

Ruud Helderman


I found the solution after examining our source control. There was an incorrect merge (in git) which caused our solution to have 2 nested projects

Project(...) = ... Project(...) = ... EndProject Global ....... 

and the last EndProject was missing. What's interesting is that Visual Studio didn't fail even though our solution file was effectively corrupt.

Adding an EndProject between the 2 Projects fixed the error.

like image 24
sashoalm Avatar answered Sep 20 '22 05:09

sashoalm