Nuget restore: Exception was thrown by the target of the call

When I run nuget restore

from the command line I get

Parse solution file at MyProject.sln: An exception was thrown by the target of the call.

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

+3


source to share


4 answers


This error is especially frustrating for large solutions with many projects, as there is no clue from NuGet at the time the file failed to parse.

To analyze the problem, try msbuild MyProject.sln

; the msbuild parser is a little more verbose. At least this will give you the line number, so you know where to look for the error. Open MyProject.sln

in a text editor to check this line. In my case, it was just an empty string that accidentally appeared while manually resolving a conflict with a TFS merge.



(It might seem like an obvious call msbuild

, but in our case the call was part of a larger build script where it nuget restore

came first, interrupting the build process before msbuild

.)

A more detailed error message should appear in a future version of NuGet; see issue # 1150 .

+9


source


I found the solution after researching our control source. 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 work even though our solution file was corrupted.

Adding EndProject between 2 projects fixed the bug.

+4


source


I had the same problem. The problem was that the sln file has the same blank lines. I removed the lines. He allowed

Ex Problem

//Blank Line
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1

    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Debug|Any CPU.Build.0 = Debug|Any CPU

        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Prod|Any CPU.ActiveCfg = Prod|Any CPU
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Prod|Any CPU.Build.0 = Prod|Any CPU
    EndGlobalSection

      

Fixed version

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1

    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Debug|Any CPU.Build.0 = Debug|Any 
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Prod|Any CPU.ActiveCfg = Prod|Any CPU
        {658E5ED2-A01E-41DD-A952-F5EDE9E4AEE0}.Prod|Any CPU.Build.0 = Prod|Any CPU
    EndGlobalSection

      

+1


source


This can also happen after installing VS 2017 15.7, but without installing .Net 4.7.2.

See more here: https://github.com/NuGet/Home/issues/6918

+1


source







All Articles