ReloadPreview 3.0.7
dotnet add package ReloadPreview --version 3.0.7
NuGet\Install-Package ReloadPreview -Version 3.0.7
<PackageReference Include="ReloadPreview" Version="3.0.7" />
paket add ReloadPreview --version 3.0.7
#r "nuget: ReloadPreview, 3.0.7"
// 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
ReloadPreview
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 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.4 is compatible. net6.0-maccatalyst was computed. net6.0-maccatalyst15.4 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. |
-
.NETStandard 2.0
- System.Text.Json (>= 6.0.2)
-
net6.0
- System.Text.Json (>= 6.0.2)
-
net6.0-android31.0
- System.Text.Json (>= 6.0.2)
-
net6.0-ios15.4
- System.Runtime.InteropServices.NFloat.Internal (>= 6.0.1)
- System.Text.Json (>= 6.0.2)
-
net6.0-maccatalyst15.4
- System.Runtime.InteropServices.NFloat.Internal (>= 6.0.1)
- System.Text.Json (>= 6.0.2)
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 | 559 | 7/12/2022 | |
3.0.6 | 539 | 4/21/2022 | |
3.0.5 | 445 | 3/3/2022 | |
3.0.4 | 436 | 2/27/2022 | |
3.0.3 | 454 | 2/27/2022 | |
3.0.2 | 459 | 2/27/2022 | |
2.1.8 | 311 | 12/22/2021 | |
2.1.7 | 282 | 12/22/2021 | |
2.1.6 | 304 | 12/14/2021 | |
2.1.5 | 356 | 12/14/2021 | |
2.1.4 | 517 | 12/11/2021 | |
2.1.3 | 1,320 | 12/3/2021 | |
2.1.2 | 717 | 12/3/2021 | |
2.1.1 | 299 | 12/3/2021 | |
2.1.0 | 310 | 12/2/2021 | |
2.0.0 | 1,605 | 12/1/2021 | |
1.2.0 | 313 | 11/28/2021 | |
1.0.0 | 374 | 10/13/2021 |
build for maui rc1