-
Notifications
You must be signed in to change notification settings - Fork 10k
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
dotnet watch
removes console color
#25317
Comments
Here's the minimal repro: https://github.com/zbecknell/Preview8Repro |
Also note: my other logging output destinations are still receiving entries just fine, so it's just the console that's affected. |
Thanks for contacting us. |
Had the exactly the same issue, I managed to get it working, however a bit hacky. In the LaunchSettings.json, set command name to something other than 'Project', that seems to mess it up. for example. "commandName": "ProjectX". "Project" launches Kestrel but without a valid name it loads Kestrel anyway, you do get an error message but it still works. Seems to have something to do with Kestrel launch.
|
@danlofquist Thanks for this workaround! Note that it does disable browser auto-launch and auto-reload when using |
It seems to work now, at least on Mac! |
Same problem here .NET SDK (reflecting any global.json): Runtime Environment: |
Same problem here
|
Same issue.
|
I'm having exactly the same issue, this was working correctly before transitioning to .NET 5. Interestingly I have two projects in the solution, one for an ASP core API and another for a Blazor server application. I can see no difference between either configuration however when running 'dotnet watch run' the API outputs colour correctly, the Blazor application is only in black and white. |
I also had this problem with .NET 5. I found that the problem was a misconfiguration in my |
For me the issue looks like it has something to with the Repro
I wonder if the web socket refresh server is messing up the color output. I have not had the time to look into this yet, but perhaps it has to do with the following: aspnetcore/src/Tools/dotnet-watch/src/LaunchBrowserFilter.cs Lines 65 to 67 in 7d73bda
|
Alright, so I finally had time to dig into this. It's the browser launch specifically that's the culprit. This is because the browser launch depends on reading the standard output from the underlying When the process is started if it has any handler attached to
When this happens we lose our colors. The What to do? Given the way this works right now, we cannot have colors and launch the browser (unless there's a way to stop redirecting output when the process has already started, which I didn't find). The downside is that we also lose the excellent auto-refresh feature, which as far as I can tell could run completely separately from the browser launching. So my proposal for a fix is to simply decouple the two and allow the refresh server to launch without also needing the browser to launch. I am submitting a simple PR that just moves the refresh server code out of the |
Still an issue - surprised this hasn't got more attention as I find the colours really useful. Removing |
That is such an odd fix... Hopefully the dotnet cli team can fix this the right way. |
I think the title of this issue probably masks the fact it's still happening today even in .net 6, not sure if the title could mention .net 6 and it might be looked at? |
dotnet watch
removes console color
Any news for upcoming .net 7? |
Another workaround that might not affect other devs on the team - set this environment variable before running
In
|
Bump. It's been a year and still just as frustrating. |
still happening! removing the |
I'm also getting this with a simple command line application. .net 8. |
Can confirm on .net 8 blazor created with |
Can confirm this with a web api app. It is insane, that this issue hasn't been fixed for so long. |
So I found a solution: set
Or in appsettings.json:
Read the configuration:
|
Thank you @iappwebdev, your work around works! |
The It's still a bit similar to turning off browser starting though. As browser starting does not work if you turn it on. I created an issue for Serilog here serilog/serilog-sinks-console#156. Given everything, not starting the browser sounds like the tradeoff I'm willing to take. |
We're almost at .NET 9 and this still hasn't been fixed. |
Applying the suggestion of setting $env:DOTNET_WATCH_SUPPRESS_LAUNCH_BROWSER=1 has worked, so that's good. I'm shocked this hasn't been taken care of yet though. Do most people not use watch? |
Describe the bug
Whatever changed with how the console output is redirected in preview 8 causes the colors and extra logging to go missing. The below output compares running
dotnet run
anddotnet watch run
:To Reproduce
Create a new blank hosted project:
Then run both
dotnet run
anddotnet watch run
on the Server project. Notice there are no colors withwatch
as well as less output.For example, I can add this to the
WeatherForecastController.Get()
method:Now view the difference in output when navigating to the Fetch Data page:
Further technical details
dotnet --info
Tested in Windows Terminal and VS Code terminal.
The text was updated successfully, but these errors were encountered: