dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.63k stars 409 forks source link

How to get reload to work outside of Visual Studio? #835

Closed Kralizek closed 6 days ago

Kralizek commented 10 months ago

I'm trying to get my services reloaded automatically while working with JetBrains Rider.

I've tried the following:

DamianEdwards commented 10 months ago

'dotnet watch' works from the command line but will tear down more than required until it's updated to implement the launch semantics. Same goes for Rider.

Kralizek commented 4 months ago

Just an update here: as far as I see, using dotnet watch --project AppHost run doesn't restart resource projects when modified. It works hitting CTRL+R on the terminal, but I would love the same experience as in tye run --watch

rcocks-hl commented 2 months ago

Hitting CTRL+R also has the large downside of restarting everything.

Ideally just the affected project would be reloaded.

Kralizek commented 2 months ago

Projects are actually reloaded but some visual cue when a project is reloaded/restarted in the AppHost log would be a nice thing to have.

DamianEdwards commented 2 months ago

dotnet watch is being updated to better hand Aspire AppHost projects: https://github.com/dotnet/sdk/issues/36971

ctolkien commented 1 month ago

Is reload supposed to work even within VS right now? We're having to explicitly build again (which restarts all services)

rcocks-hl commented 1 month ago

@DamianEdwards Has that effort stalled?

DamianEdwards commented 1 month ago

It depends on what one means by reload. Hot Reload works for supported changes in the app projects but not in the AppHost project. Auto-rebuild and restart of app projects works in VS for app projects when launching without debugging but changes to the AppHost will cause all apps to restart. dotnet watch has been updated to better support Aspire scenarios and will be available in the .NET 9 SDK I believe.

This is a complicated problem which we will continue to make progress on release to release.

rcocks-hl commented 1 month ago

Thanks @DamianEdwards, I'll try with the .net 9 SDK to see if there have been improvements. It may be that this has worked how I'd expect, but I haven't been aware due to the lack of logging in the console when launching via the apphost. Hopefully the .NET 9 SDK update brings that kind of improvement.

DamianEdwards commented 1 month ago

Aspire 8.1 added more logging in the AppHost project in that it now forwards logs from the resources being orchestrated. You can of course adjust the logging levels and filters too to see more logs.

rcocks-hl commented 1 month ago

@DamianEdwards I've tried again with Aspire 8.1, albeit on SDK v8.0.7 and I've been unable to get the message I'm interested forwarded.

In apphost I do now see forwarded messages, but the specific message that would normally be generated when running individually do not get forwared.

For example, running dotnet watch --project .\AspireSample.Web\ and changing Components\Pages\Home.razor. results in a console message:

dotnet watch ⌚ File changed: .\AspireSample.Web\Components\Pages\Home.razor.

And the page is updated live while viewing, without refreshing.

This message does not appear to be a standard ILogger format message.

Launching watch via the appHost however: dotnet watch --project .\AspireSample.AppHost\

And changing the same file.

Does not result in any log, and the change is not "pushed" to the client.

Manually refreshing reveal the change has been hot-reloaded in the background.

I'll test again with the .NET 9 SDK to compare. I'll need to wait until I'm on my home account for that.

DamianEdwards commented 1 month ago

This message does not appear to be a standard ILogger format message.

Correct. That message is emitted by dotnet watch itself, not your applications.

I'll test again with the .NET 9 SDK to compare. I'll need to wait until I'm on my home account for that.

I believe this should work in the .NET 9 SDK as it has the dotnet watch updates, right @davidfowl?

davidfowl commented 6 days ago

The work isn't in yet. It's still in a pull request. Track https://github.com/dotnet/sdk/issues/36971