dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.93k stars 4.02k forks source link

Restore.cmd: exception thrown when trying to run in some cases. #21754

Open dezsiszabi opened 7 years ago

dezsiszabi commented 7 years ago

Version Used: Latest version from master.

Steps to Reproduce:

  1. Open a cmd.exe and navigate to Restore.cmd. Make sure it's not a developer command prompt and you don't have the VSINSTALLDIR environment variable set.
  2. Go to your NuGet packages folder and delete the vswhere package. I had two folders: vswhere and vswhere.1.0.71. It's usually under %USERPROFILE%\.nuget\packages
  3. Run Restore.cmd

Expected Behavior: Should download vswhere and move on with the NuGet restore process.

Actual Behavior: You get the below output:

h:\Practice\GitHub\roslyn>Restore.cmd
Repo Dir H:\Practice\GitHub\roslyn
Binaries Dir H:\Practice\GitHub\roslyn\Binaries
Using existing NuGet.exe at version 4.1.0
Illegal characters in path.
Using existing NuGet.exe at version 4.1.0
Illegal characters in path.
Command failed to execute:  & $nuget install $name -OutputDirectory (Get-PackagesDir) -Version $version
System.Management.Automation.RuntimeException: Command failed to execute:  & $nuget install $name -OutputDirectory (Get-PackagesDir) -Version $version
at Exec-Block, H:\Practice\GitHub\roslyn\build\scripts\build-utils.ps1: line 26
at Ensure-BasicTool, H:\Practice\GitHub\roslyn\build\scripts\build-utils.ps1: line 128
at Get-MSBuildDirXCopy, H:\Practice\GitHub\roslyn\build\scripts\build-utils.ps1: line 264
at Get-MSBuildKindAndDir, H:\Practice\GitHub\roslyn\build\scripts\build-utils.ps1: line 258
at Ensure-MSBuild, H:\Practice\GitHub\roslyn\build\scripts\build-utils.ps1: line 137
at Ensure-MSBuildAndDir, H:\Practice\GitHub\roslyn\build\scripts\build-utils.ps1: line 157
at <ScriptBlock>, H:\Practice\GitHub\roslyn\build\scripts\build.ps1: line 512

Reason As far as I know NuGet doesn't support a trailing '\' in its OutputDirectory parameter*. The Get-PackagesDir function is used to calculate what's passed to NuGet as an argument.

Solution I have a solution which I can submit as a PR once you confirm this issue. Adding .TrimEnd("\") in Ensure-BasicTool to what's passed to NuGet solves this. The reason I don't propose changing this in Get-PackagesDir is because that's called from multiple places and could break other things if something else expects the trailing '\' to be there.

*Source: https://github.com/NuGet/home/issues/1817 https://github.com/NuGet/NuGet.Client/commit/f47b115f2577fa0304d5b595ac86ef2d4cfab605

jasonmalinowski commented 7 years ago

@jaredpar Any opinion if @dezsiszabi's proposed fix is safe?

jaredpar commented 7 years ago

Should be fine

jasonmalinowski commented 7 years ago

@dezsiszabi Is this a fix you'd want to try?

dezsiszabi commented 7 years ago

@jasonmalinowski Yes, it's a very minor change. I already tested in on my computer and it works for me. Can I submit the PR?

jasonmalinowski commented 7 years ago

@dezsiszabi Of course! Go right ahead. :-)