ReloadPreview 3.0.7

.NET 6.0 .NET Standard 2.0
Install-Package ReloadPreview -Version 3.0.7
dotnet add package ReloadPreview --version 3.0.7
<PackageReference Include="ReloadPreview" Version="3.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ReloadPreview --version 3.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ReloadPreview, 3.0.7"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.7

// Install ReloadPreview as a Cake Tool
#tool nuget:?package=ReloadPreview&version=3.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ReloadPreview

image

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)
  • net6.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;
    }
}

Notice:If you build at windows, you need let VisualStudio for Windows link to Mac, otherwise maybe generate dll is not correct.

At not Android and iOS, maybe you need load ReloadClass< T > in UI thread,such as at 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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-android31.0 net6.0-ios net6.0-ios15.4 net6.0-maccatalyst net6.0-maccatalyst15.4 net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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.

Version Downloads Last updated
3.0.7 75 7/12/2022
3.0.6 115 4/21/2022
3.0.5 93 3/3/2022
3.0.4 81 2/27/2022
3.0.3 82 2/27/2022
3.0.2 88 2/27/2022
2.1.8 118 12/22/2021
2.1.7 105 12/22/2021
2.1.6 111 12/14/2021
2.1.5 139 12/14/2021
2.1.4 320 12/11/2021
2.1.3 1,105 12/3/2021
2.1.2 527 12/3/2021
2.1.1 115 12/3/2021
2.1.0 113 12/2/2021
2.0.0 1,402 12/1/2021
1.2.0 113 11/28/2021
1.0.0 189 10/13/2021

build for maui rc1