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?
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?
I had the same problem. This happened on our CI-server (TFS 2018) when using the "Nuget restore" task. Appearantly the build agent was using an old version of nuget (4.1) and it had trouble reading the Visual Studio 2019 solution file (sln and/or csproj) resulting in the error indicated by @sashoalm.
The answer from Microsoft was to use the task "Nuget Tool Installer" but this was not working behind the enterprise proxy wall that I am behind. From what I have read people have a hard time with this. According the Microsoft they have resolved this but only in Azure Devops Server 2019 in an update to the "Nuget tool installer" task.
What is the resolution is to manually download the nuget.exe of your choice and copy it to the build agent. Then, replace your "Nuget" task with a "Powershell" task and do
Write-Host "Restoring packages"
Write-Host "Using nuget.exe at" $(nugetexepath)
$(nugetexepath) restore [PATH_TO_SLN_FILE] -Verbosity Detailed -NonInteractive
I added a variable
nugetexepath
as well in the build configuration.
Perhaps this gets resolved in a future update from Microsoft to help all that are still on TFS 2018 and not on Azure Devops Server 2019.
This can also happen after installing VS 2017 15.7 but without having .Net 4.7.2 installed.
See here for more details: https://github.com/NuGet/Home/issues/6918
I got this error from my azure pipeline. I went onto the build server & ran msbuild mysolution.sln. That revealed a different error:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)
at Microsoft.Build.CommandLine.MSBuildApp.Main()
That's when I found that I found this answer Could not load file or assembly 'Microsoft.Build.Framework'(VS 2017) & thought I needed to update nuget, so I added a step in my pipeline for the NuGet Installer task & set it to use a newer version.
https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/nuget?view=azure-devops
No more errors.