microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
234 stars 13 forks source link

[BUG] MAUI extension does not show console output for MacCatalyst #1090

Open jonathanpeppers opened 6 months ago

jonathanpeppers commented 6 months ago

Describe the Issue

If I add Console.WriteLine("Hello!") in a .NET MAUI application running on macOS, I don't see the message in VS Code's "Debug Console".

However, if I run the app such as:

$ ./bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/MyApp.app/Contents/MacOS/MyApp 
2024-04-30 11:39:27.336 MyApp[28217:8881808] You've implemented -[<UIApplicationDelegate> application:performFetchWithCompletionHandler:], but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.
2024-04-30 11:39:33.138 MyApp[28217:8881808] Hello!

Then I see the message.

Steps To Reproduce

  1. dotnet new maui
  2. Add a Console.WriteLine("Hello!") somewhere in the app
  3. Run the project in VS Code
  4. The log message does not appear

Expected Behavior

I can see CWL messages in the "Debug Console" window.

Environment Information

phillippschmedt commented 2 months ago

I face the same issue when debugging .NET MAUI on iOS.

hugebug4ever commented 3 days ago

It's the expected behaviour.
You should use Debug.WriteLine("xxxx) to output to the "vs code debug console". "Console.WriteLine" is designed for console environment , not "deug console"

I think this issue could be closed.

Image

jonathanpeppers commented 3 days ago

@hugebug4ever Console.WriteLine() has always appeared in IDEs for applications running on the Mono runtime: iOS, Android, MacCatalyst.

I wouldn't expect this behavior in VS Code should differ from VS Mac or VS Windows?

hugebug4ever commented 2 days ago

@jonathanpeppers sorry for my reckless, I didn't notice you are from official team. I have just adapted to "console to console window" and "debug to debug window". It behaved the same with latest dotnet core application with vs2022.
Just wondering why should we pipe the Console.WriteLine to Debug window, but not a separate console window ? To me, this way is more clear.

jonathanpeppers commented 2 days ago

What you are describing is definitely what happens on Windows (WinUI3, MAUI, etc.). I agree with that.

I don't know if we can change the behavior for .NET mobile at this point, as it has been this way since Xamarin, .NET 6, 7, 8, 9.

@rolfbjarne might have an opinion about what it should do. But I would think they want to see both NSLog() messages and Console.WriteLine() messages? We would also want Android.Util.Log.Debug() messages to show on Android.

rolfbjarne commented 2 days ago

@rolfbjarne might have an opinion about what it should do. But I would think they want to see both NSLog() messages and Console.WriteLine() messages? We would also want Android.Util.Log.Debug() messages to show on Android.

IMO Console[.Error].Write* output should be visible somewhere from inside VS Code. If that's the "Debug console", or some other pad, I don't particularly care.

FWIW macOS / iOS forwards anything written using NSLog to stderr, so showing stderr takes care of that.