Skip to content

Include command output in restore exception message #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

DanielEgbers
Copy link

Description

The error message currently displayed when DotnetRestorer.Restore fails does not provide enough information to resolve the issue.

This PR adds the executed command and the command's output to the current error message

Current error message example:

Unable to restore packages from 'C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\.\netcoreapp3.1\script.csproj'. Make sure that all script files contains valid NuGet references

New improved error message example:

Unable to restore packages from 'C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\.\netcoreapp3.1\script.csproj'
Make sure that all script files contains valid NuGet references

Details:
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1 : dotnet restore "C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\.\netcoreapp3.1\script.csproj" -r win10-x64  --configfile "C:\Users\user\AppData\Roaming\NuGet\NuGet.Config"
  Determining projects to restore...
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605: Detected package downgrade: Microsoft.Win32.Primitives from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version.
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605:  script -> AngleSharp.Js 0.14.0 -> jint 2.10.4 -> NETStandard.Library 1.6.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> Microsoft.Win32.Primitives (>= 4.3.0)
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605:  script -> AngleSharp.Js 0.14.0 -> jint 2.10.4 -> NETStandard.Library 1.6.0 -> Microsoft.Win32.Primitives (>= 4.0.1)
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605: Detected package downgrade: System.Net.Primitives from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605:  script -> AngleSharp.Js 0.14.0 -> jint 2.10.4 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Net.Primitives (>= 4.3.0)
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605:  script -> AngleSharp.Js 0.14.0 -> jint 2.10.4 -> NETStandard.Library 1.6.0 -> System.Net.Primitives (>= 4.0.11)
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605: Detected package downgrade: Microsoft.Win32.Primitives from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version.
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605:  script -> AngleSharp.Js 0.14.0 -> jint 2.10.4 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Security.Principal.Windows 4.3.0 -> Microsoft.Win32.Primitives (>= 4.3.0)
C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj : error NU1605:  script -> AngleSharp.Js 0.14.0 -> jint 2.10.4 -> NETStandard.Library 1.6.0 -> Microsoft.Win32.Primitives (>= 4.0.1)
  Failed to restore C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\netcoreapp3.1\script.csproj (in 769 ms).

Motivation and Context

I had a problem which I could not solve with the current error message

Problem:

  1. Create a script with this content
#r "nuget: AngleSharp.Js, 0.14.0"
#r "nuget: Microsoft.SyndicationFeed.ReaderWriter, 1.0.2"
Console.WriteLine("it works");
  1. Execute the script (using the .net core 3.1 binary of dotnet-script. with .net core 2.5 binary it would work)
  2. It fails and the current error message example from above is displayed
  • Both nuget packages exist
  • Running dotnet restore manually on C:\Users\user\AppData\Local\Temp\dotnet-script\D\scripts\.\netcoreapp3.1\script.csproj works
  1. At this point there is no way to resolve the issue without having to build and debug dotnet-script

How does this change help?

  • Knowing the executed command would help because then I would notice that dotnet restore is run with -r win10-x64. With this argument it fails, without it it works
  • Knowing the output of the executed command you can easily tell why the restore fails and how to fix it. Nuget cannot determine the version of two dependencies.

With these information I can finally run the script by changing it to this:

#r "nuget: Microsoft.Win32.Primitives, 4.3.0"
#r "nuget: System.Net.Primitives, 4.3.1"
#r "nuget: AngleSharp.Js, 0.14.0"
#r "nuget: Microsoft.SyndicationFeed.ReaderWriter, 1.0.2"
Console.WriteLine("it works");

Copy link
Collaborator

@seesharper seesharper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. If you include a test for this I think this is good to go 👍

@DanielEgbers
Copy link
Author

I added unit tests for DotnetRestorer

Copy link
Collaborator

@seesharper seesharper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@seesharper seesharper requested a review from filipw October 25, 2020 21:30
Copy link
Member

@filipw filipw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@filipw filipw merged commit 120ff8e into dotnet-script:master Oct 26, 2020
@DanielEgbers DanielEgbers deleted the bugfix/DotnetRestorerErrorDetails branch October 26, 2020 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants