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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With