adospace / reactorui-maui

MauiReactor is a MVU UI framework built on top of .NET MAUI
MIT License
586 stars 49 forks source link

Hot reload for windows app #55

Closed freever closed 1 year ago

freever commented 1 year ago

Hi @adospace

This is an awesome library, thanks for putting it out there!

Is hot reload supposed to work for windows apps? I have tested dotnet-maui-reactor for Android in normal and full mode and both work as expected, but when I run under windows I get errors.

Under normal mode:

PS C:\Code\Blauhaus\Blauhaus.Accounts\src\sample\accounts.sample.client.mauireactor> dotnet-maui-reactor -f net7.0-windows10.0.19041.0
MauiReactor Hot-Reload CLI
Version 1.0.116.0
Press Ctrl+C or Ctrl+Break to quit
Setting up build pipeline for Accounts.Sample.Client.MauiReactor project...done.
Monitoring folder 'C:\Code\Blauhaus\Blauhaus.Accounts\src\sample\accounts.sample.client.mauireactor'...
Detected file rename from 'Pages\MainPage.cs' to 'Pages\MainPage.cs~RF16d2c6.TMP'
Detected file rename from 'Pages\hjd5jhbu.dzq~' to 'Pages\MainPage.cs'
Replacing syntax tree for: Pages\MainPage.cs
error CS5001: Program does not contain a static 'Main' method suitable for an entry point
C:\Code\Blauhaus\Blauhaus.Accounts\src\sample\accounts.sample.client.mauireactor\Platforms\Windows\App.xaml.cs(19,18): error CS1061: 'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?)

Under full mode it sometimes works but mostly gets stuck on this:

CSC : error CS2012: Cannot open 'C:\Code\Blauhaus\Blauhaus.Accounts\src\sample\accounts.sample.client.mauireactor\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Accounts.Sample.Client.MauiReactor.pdb' for writing -- 'The process cannot access the file 'C:\Code\Blauhaus\Blauhaus.Accounts\src\sample\accounts.sample.client.mauireactor\obj\Debug\net7.0-windows10.0.19041.0\win10-x64\Accounts.Sample.Client.MauiReactor.pdb' because it is being used by another process.' [C:\Code\Blauhaus\Blauhaus.Accounts\src\sample\accounts.sample.client.mauireactor\Accounts.Sample.Client.MauiReactor.csproj::TargetFramework=net7.0-windows10.0.19041.0]

If windows is not supported, that's fine, but if it is then let me know if you need any further info.

Apart from the dotnet-maui-reactor tool, Is there anything specific required to get "normal" maui hotreload to work?

Thanks again

adospace commented 1 year ago

Hi, thanks for your interest. Yes, hot-reload for a Windows application is supported but I know it could be cumbersome. First, the simple mode can't work as is because it can't build xaml so it has trouble with the App.xaml file under the platform folder.

The full-mode option should work most of the time, but sometimes it's unable to read the pdb file because it's locked (without an apparent reason) by Visual Studio. This should happen if you debug the application and hot-reload it simultaneously (try removing the bin & obj folder and restart visual studio).

The third option is to use the build-in dotnet hot-reload function but unfortunately, it still lacks support for many kind of edits. This is the builtin-hot-reload in action with a Windows app:

https://user-images.githubusercontent.com/10573253/229629534-c583e7f5-f2fc-4566-87d2-101611202182.mp4

To sum up:

1) Use MauiReactor hot-reload BUT without debugging the app (this should prevent VS to lock the pdb file) 2) Use the dotnet built-in hot-reload for small modifications

Please let me know if you find anything I can fix using MauiReactor full-mode hot reload

freever commented 1 year ago

@adospace

Thanks for the feedback - yes, I can confirm that options 1 and 2 both work, with their respective pros and cons. The built-in one is really quick but limited.

I'll re-open this if I find any more issues.