adospace / reactorui-maui

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

bug in hot reload #87

Closed Code-DJ closed 1 year ago

Code-DJ commented 1 year ago

Hot reload does not set the DEBUG flag. See example below. On change of any file in the project, hot reload kicks in causing Foo to get recreated but logic doesn't go through if DEBUG, writes RELEASE to the console and Bar is set to null.

public class Foo
{
    static readonly string Bar;

    static Foo()
    {
#if DEBUG
        Console.WriteLine("DEBUG");
        Bar = "Testing 123";
#else
        Console.WriteLine("RELEASE");
        Bar = null!;
#endif
    }
}
adospace commented 1 year ago

hum, by default, using the mauireactor template hot-reload is not configured at all under Release mode: image

and running the project in debug the #else branch above shouldn't go in the compile code at all.

are you running the app under Release or Debug? can you post a small project showing the issue?

Code-DJ commented 1 year ago

I have it the same way.

#if DEBUG
            .EnableMauiReactorHotReload()
#endif

Run the following in first terminal: dotnet build -t:Run -f net7.0-ios /p:_DeviceName=:v2:udid=***

Run the following in second terminal: dotnet-maui-reactor -f net7.0-ios

Changed from static variable and constructor to instance variable and constructor, moved the #if DEBUG one level up where the class gets instantiated. Closing thanks!

Code-DJ commented 1 year ago

Hi, there is a bug in hot reload - not sure how it works behind the scenes but I assume it builds and loads a new assembly in the background - this assembly is being built in Release mode.

Code-DJ commented 1 year ago

UPDATE: Tried both options, still shows RELEASE.

Looks like it is being built in debug mode but the DEBUG constants is not being set DefineConstants. Visual Studio automatically does this for us. May be we need to pass it here?

https://github.com/adospace/reactorui-maui/blob/39cb1de97f918854b895a4909d2dcc709cdba55d/src/MauiReactor.HotReloadConsole/HotReloadClientEmit.cs#L55

{ "DefineConstants", "DEBUG;TRACE" }

or is it?

{ "DebugSymbols", "true" }

adospace commented 1 year ago

Hi, sorry, but can't look at the issue before Wednesday next week, hopefully it is not a problem for you