Skip to content

[BUG?] Hot Reload not working in VS Code #87

@Sorrow-Scarlet

Description

@Sorrow-Scarlet

Overview

Trying to use hot reload, after reading hotreload.md in Docs.

I found that hot reload is not working at all.

Am I using it wrong?

Walkthrough

MewUiHotReload.RequestReload([typeof(MainView)])
  • Bind above code to OnMouseEnter event
  • Bind above code to Btn OnClick event
  • Not bind to any event

MewUI Info

  <ItemGroup>
    <PackageReference Include="Aprillz.MewUI" Version="0.14.0" />
  </ItemGroup>

OS Info

Operating System

  • Name: Microsoft Windows 11 Home CN
  • Version: 10.0.26100
  • Architecture: 64 bits
  • Build: 26100
  • Manufacturer: Microsoft Corporation

CPU

  • Processor Name: Intel(R) Core(TM) i5-14400
  • Cores: 10
  • Logical Processors: 16
  • Clock Speed: 2500 MHz

Memory

  • Total Physical Memory: 16 GB
  • Memory Type: 0

Ref Code

// ApplicationBuilder.cs
public static class ApplicationBuilder
{
    static readonly IconSource _Icon = IconSource.FromResource<MainView>("app_64_r.ico");
    static readonly string _AppTitle = "MVZ2SaveEditor";

    public static void Build()
    {
        RegisterPlatforms();
        CreateApp();
    }

    public static void HotBuild()
    {
        RegisterPlatforms();
        CreateHotApp();
    }

    private static void RegisterPlatforms()
    {
#if TARGET_WINDOWS
        Win32Platform.Register();
        Direct2DBackend.Register();

#elif TARGET_LINUX && !TARGET_ANDROID
        X11Platform.Register();
        MewVGX11Backend.Register();

#elif TARGET_OSX
        MacOSPlatform.Register();
        MewVGMacOSBackend.Register();
#endif
    }

    private static void CreateApp()
    {
        Application
            .Create()
            .BuildMainWindow(() =>
                new Window()
                    .Resizable(1280, 720)
                    .OnLoaded(() => { })
                    .OnClosed(() => { })
                    .Title(_AppTitle)
                    .Padding(8)
                    .Icon(_Icon)
                    .Content(new MainView(new MainVM()))
            )
            .Run();
    }

    private static void CreateHotApp()
    {
        var mv = new MainView(new MainVM());
        var window = new Window().OnBuild(x =>
            x.Resizable(1280, 720)
                .OnLoaded(() => { })
                .OnClosed(() => { })
                .Title(_AppTitle)
                .Padding(8)
                .Icon(_Icon)
                .Content(
                    new StackPanel()
                        .Spacing(8)
                        .Children(
                            mv,
                            new Button()
                                .Content("Reload")
                                .OnClick(() => MewUiHotReload.RequestReload([typeof(MainView)]))
                        )
                )
        );

        Application.Create().Run(window);
    }
}
// MVZ2SaveEditor.cs (The Program.cs with alias)
using MVZ2SaveEditor.Utils;
#if DEBUG

[assembly: System.Reflection.Metadata.MetadataUpdateHandler(
    typeof(Aprillz.MewUI.HotReload.MewUiMetadataUpdateHandler)
)]

#endif

namespace MVZ2SaveEditor;

class MVZ2SaveEditor
{
    [STAThread]
    static void Main()
    {
#if DEBUG
        ApplicationBuilder.HotBuild();
#endif
#if !DEBUG
        ApplicationBuilder.Build();
#endif
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions