NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

Interactive nuget why command output contains Unicode characters that are unreadable in file output #13807

Open AnthonyMastrean opened 2 hours ago

AnthonyMastrean commented 2 hours ago

NuGet Product Used

dotnet.exe

Product Version

.NET SDK 8.0.401

Worked before?

No

Impact

It bothers me. A fix would be nice

Repro Steps & Context

Interactive output has these fancy tree characters.

PS> dotnet nuget why .\example\ "Newtonsoft.Json"
Project 'Example' has the following dependency graph(s) for 'Newtonsoft.Json':

  [net7.0]
   │  
   └─ Newtonsoft.Json (v13.0.3)

But those don't survive into a file whether by Out-File or Set-Content with or without any -Encoding utf8.

Project 'Example' has the following dependency graph(s) for 'Newtonsoft.Json':

  [net7.0]
   Γöé  
   ΓööΓöÇ Newtonsoft.Json (v13.0.3)

Verbose Logs

No response

AnthonyMastrean commented 2 hours ago

Would be mitigated by machine-readable output (#13649)

jeffkl commented 1 hour ago

I'm going to close this as not a bug since this has more to do with the encoding used by whatever system writes the output to a file.

Running this command in a Windows command-line window works fine:

dotnet nuget why ClassLibrary1.csproj NuGet. > test.txt

The file emitted looks like:

Project 'ClassLibrary1' has the following dependency graph(s) for 'Newtonsoft.Json':

  [net6.0]
   │  
   └─ Newtonsoft.Json.Bson (v1.0.2)
      └─ Newtonsoft.Json (v12.0.1)

Running this in PowerShell works with -Encoding Oem but not -Encoding Unicode:

dotnet nuget why ClassLibrary1.csproj Newtonsoft.Json | Set-Content .\test.txt -Encoding Oem
Project 'ClassLibrary1' has the following dependency graph(s) for 'Newtonsoft.Json':

  [net6.0]
   │  
   └─ Newtonsoft.Json.Bson (v1.0.2)
      └─ Newtonsoft.Json (v12.0.1)

NuGet itself is writing the correct characaters to STDOUT and cannot control what mechanism is used to then write the stream to a file.

If you want to use the output in a program, then we recommend you instead use the JSON output.