ReloadPreview 3.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package ReloadPreview --version 3.0.5                
NuGet\Install-Package ReloadPreview -Version 3.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ReloadPreview" Version="3.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReloadPreview --version 3.0.5                
#r "nuget: ReloadPreview, 3.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ReloadPreview as a Cake Addin
#addin nuget:?package=ReloadPreview&version=3.0.5

// Install ReloadPreview as a Cake Tool
#tool nuget:?package=ReloadPreview&version=3.0.5                

ReloadPreview

NuGet version(ReloadPreview)

Command Line Server

What is ReloadPreview

We know we can preview the ui when use xaml,xml,storyboard,swiftui, but if you want use C# code to write ui, no preview? Now, you can use this library to do it. It not only preview, because it need run app, that mean you can show data and load service, and debug by print info.

Support platform

  • net6.0-android (tested)
  • net6.0-ios (tested, can't directly reload object that extend object-c)
  • new6.0 and netstandard (such as maui-windows,or avalonia,need load ReloadClass< Control > in UI thread)

Need other platform? Invoke UI thread when change ui at Reload event, or override InvokeInMainThread method.

How it work

After code changed, Command Line Server use msbuild to create new dll, then use socket send the .dll to android or ios app, app can use reflection to create instance from dll. So, you can remove old view form window, and use this instance of new view to do something.

Notice: you must let reloaded class is public, because it is reload another assembly.

How to use

Install and Run Command Line Server , input proj and target, such as D:/RelodPreview/ReloadPreview.csproj -t=android. Them install nuget, use it, such as at MAUI app:

public App()
{
    HotReload.Instance.Init("192.168.0.108");
    InitializeComponent();
    HotReload.Instance.Reload += () =>
    {
        var view = HotReload.Instance.ReloadClass<MainPage>() as Page;
        Console.WriteLine(view is null);
        MainPage = view;
    };
    MainPage = new MainPage();
}

At ios platform,you can't reload class that extend from native object-c class, such as UIView,UIViewController,you can reload view like this:

public MainController(UIWindow window)
{
    HotReload.Instance.Init("192.168.0.108");
    HotReload.Instance.Reload += () =>
    {
        dynamic view = HotReload.Instance.ReloadClass<MainPage>(window!.Frame);
        this.View = view.Get() as UIView;
    };
    this.View = new MainPage(window!.Frame).Page;
}
public class MainPage
{
    public UIView Page;
    public MainPage(CGRect frame)
    {
        Page =  new UILabel(frame)
        {
            BackgroundColor = UIColor.Red,
            TextAlignment = UITextAlignment.Center,
            Text = "Hello,net6-ios!"
        };
    }

    public UIView Get()
    {
        return Page;
    }
}

At not MAUI support others Ui framework, maybe you need load ReloadClass< T > in UI thread,such as Avalonia:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
#if DEBUG
        this.AttachDevTools();
#endif

#if DEBUG
        HotReload.Instance.Reload += () =>
        {
            Dispatcher.UIThread.Post(() =>
            {
                var view = HotReload.Instance.ReloadClass<MainPage>();
                this.Content = view;
            });
        };
        HotReload.Instance.Init("192.168.0.108");
#endif
    }
}

Tips

  • 2021.10.21

    I found when you close "Edit and Continue" at Visual Studio 2022, you can use "Apply Changes" of Visual Studio to continue simple debug Android, At Android, "Apply Changes" will kill current Activity, and reload the Activity in apk, it can't let app auto load the new dll, so ReloadPreview can help you reload all the things of the activity. Limit is you just can use old breakpoint.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-android31.0 is compatible.  net6.0-ios was computed.  net6.0-ios15.2 is compatible.  net6.0-maccatalyst was computed.  net6.0-maccatalyst15.2 is compatible.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

created for maui single project