HotAvalonia

2025-12-07 0 378

HotAvalonia

HotAvalonia is a hot reload plugin for Avalonia that enables you to see UI changes in real time as you edit XAML files, drastically accelerating your design and development workflow.


NuGet Packages

Package Latest Version
HotAvalonia
HotAvalonia.Core
HotAvalonia.Extensions
HotAvalonia.Fody

Installation

To instantly enable hot reload for Debug builds of your application, simply add the HotAvalonia package to your startup project (i.e., the project that produces the executable) by inserting the following snippet into your project file (e.g., .csproj, .fsproj, .vbproj, etc.):

<PackageReference Include=\"HotAvalonia\" Version=\"...\" PrivateAssets=\"All\" Publish=\"True\" />

If you\’re developing a mobile app, please double-check that Publish=\"True\" is set. Otherwise, Debug builds of your app will immediately crash on startup due to an old .NET SDK bug (dotnet/sdk#47332).

If you have a multi-project setup, it is highly recommended to add HotAvalonia to every project that contains Avalonia controls. You can either do this manually for each project, or include a PackageReference to HotAvalonia in your Directory.Build.targets.

HotAvalonia is a development-only dependency, meaning it doesn\’t affect your Release builds in any way, shape, or form, and its binaries are not shipped with your application.


Examples

Here are some examples demonstrating HotAvalonia in action:

To try it out yourself, you can run the samples/HotReloadDemo.Desktop and/or samples/HotReloadDemo.Android applications included in the repository.


Usage

HotAvalonia is designed in such a way that you usually don\’t need to do anything else after installation – it just works™. However, here are some tips and tricks for more advanced users who want to tweak their hot reload experience:

[AvaloniaHotReload]

If you want to refresh a control\’s state during a hot reload, you can apply the [AvaloniaHotReload] attribute to one or more parameterless instance methods of the said control. For example:

  using Avalonia.Controls;
+ using HotAvalonia;

  public partial class FooControl : UserControl
  {
      public FooControl()
      {
          InitializeComponent();
          Initialize();
      }

+     [AvaloniaHotReload]
      private void Initialize()
      {
          // Code to initialize or refresh
          // the control during hot reload.
      }
  }

\’StaticResource\’

When you reference a static resource, Avalonia effectively inlines its value, turning it into a constant. As a result, hot reloading a resource dictionary, for example, from which the value originally came will not affect any StaticResource definitions – you would need to hot reload the document containing them for those constant values to be recomputed.

However, if you\’re actively working on something referenced this way, having to hot reload two documents at a time just to see the changes can be pretty annoying. To make this a bit more convenient, you can use a special \'StaticResource\' syntax like this:

<TextBox Watermark=\"{\'StaticResource\' Watermark}\" />

This syntax is valid because Avalonia\’s parser allows quoting parts of your queries. However, since no sane person would ever quote StaticResource under normal circumstances, HotAvalonia treats it as a virtue signal to dynamically replace it with a DynamicResource at runtime.

With this trick, your production builds will retain the intended semantics of optimized and inlined static resources, while your debug builds empowered by HotAvalonia will convert those resources into dynamic ones, making hot reloading them much more convenient.

MSBuild Properties

HotAvalonia is highly configurable, and lots of its options can be adjusted via MSBuild properties directly in your project file (e.g., .csproj, .fsproj, .vbproj), like so:

<PropertyGroup>
  <HotAvaloniaLite>enable</HotAvaloniaLite>
</PropertyGroup>

Below is a non-exhaustive list of the most common and useful properties supported by HotAvalonia:

Name Description Default Examples
HotAvalonia Specifies whether HotAvalonia is enabled in the current environment.

Please, do not enable HotAvalonia unconditionally.

true if current configuration is Debug; otherwise, false. enable
disable
true
false
HotAvaloniaRemote Specifies whether the app will be executed on a remote device (e.g., when running the app in an emulator). true for Android, iOS, and browser builds; otherwise, false. enable
disable
true
false
HotAvaloniaLite Specifies whether HotAvalonia should disable some of its more resource-intensive features, such as automatic hot reload of images and icons. The same value as HotAvaloniaRemote. enable
disable
true
false
HotAvaloniaIncludeExtensions Specifies whether the AvaloniaHotReloadExtensions class should be included in the current project.

This class provides extension methods like .UseHotReload() necessary to enable hot reload for your application.

true if the current project is a startup project; otherwise, false. true
false
HotAvaloniaAutoEnable Specifies whether hot reload should be enabled automatically or if the user should manually call .UseHotReload() on their AppBuilder instance. true if the current project is a startup project; otherwise, false. true
false
HotAvaloniaRecompileResources Specifies whether HotAvalonia should recompile resources like styles and resource dictionaries to make them hot-reloadable even on non-x64 devices. true true
false
HotAvaloniaGeneratePathResolver Specifies whether HotAvalonia should generate a project path resolver during compile-time based on your solution file (i.e., .sln), or if it should search for source project locations during runtime.

Resolving project paths at runtime may be more reliable in some situations, but it\’s also a tiny bit more time-demanding solution.

true true
false

Also, if you are using hot reload on a remote device (for example, if you are developing a mobile app), there are some additional options to configure HotAvalonia.Remote (also known as HotAvalonia Remote File System, or just HARFS for short):

Name Description Default Examples
HarfsAddress Specifies the address of the machine that hosts the source code of the app (i.e., the machine on which you built the application). The IPv4 address of your machine within the local network. 192.168.0.42
HarfsFallbackAddress Specifies a fallback address of the machine hosting the source code, in case HotAvalonia cannot resolve your computer\’s local network address. 10.0.2.2 if the target device is an Android emulator; otherwise, 127.0.0.1. 127.0.0.1
HarfsLocalAddress Specifies the address for HARFS to listen on for new client connections. 0.0.0.0
(all available network interfaces)
192.168.0.42
HarfsPort Specifies the port for HARFS to listen on for new client connections. 0
(any currently available TCP port)
20158
HarfsSecret Specifies the secret used by HARFS to authenticate new clients. My Super Secret Value
HarfsSecretBase64 Specifies the secret used by HARFS to authenticate new clients in the form of a Base64 string. A new secret is generated each time you run your app. TXkgU3VwZXIgU2VjcmV0IFZhbHVl
HarfsCertificateFile Specifies a path to the X.509 certificate file for securing connections with new clients. A new self-signed certificate is generated each time you run your app. /etc/ssl/certs/harfs.pfx
HarfsMaxSearchDepth Specifies how many files HARFS can return in a recursive directory search. 256 -1
10
2147483647
HarfsTimeout Specifies a timeout (in milliseconds) for HARFS to shut down if no clients connect within the specified time window. 300000
(5 minutes)
-1
10000
2147483647
HarfsExitOnDisconnect Specifies whether HARFS should shut down as soon as its primary client (that being your app) disconnects. true true
false

As mentioned earlier, this list is far from exhaustive. For a complete overview of available options, please check out the HotAvalonia.targets file. However, note that any properties not listed here (especially those prefixed with _) are considered internal and may be renamed, replaced, or completely removed without notice. So, feel free to experiment with those, but do not rely on them for long-term compatibility.

Optional Dependencies

To enhance your experience with HotAvalonia, you may want to install the following optional dependencies:

Name Description Snippet
Avalonia.Markup.Xaml.Loader HotAvalonia relies on this official Avalonia package to compile XAML during runtime.

To accommodate users of all Avalonia releases starting from v11.0.0, HotAvalonia includes a pretty old version of Avalonia.Markup.Xaml.Loader. So, you might want to bump it explicitly in your project file.

<PackageReference Include=\"Avalonia.Markup.Xaml.Loader\" Version=\"*\" PrivateAssets=\"All\" />
MonoMod.RuntimeDetour If this package is installed, HotAvalonia will automatically switch to injection-based hot reload, enabling some of its more advanced features, such as asset hot reloading, which are otherwise disabled. <PackageReference Include=\"MonoMod.RuntimeDetour\" Version=\"*\" PrivateAssets=\"All\" />

Miscellaneous

HotAvalonia.Core and HotAvalonia.Extensions, provided by the main HotAvalonia package, can be fine-tuned even further. For more details about their internals, please refer to their respective READMEs.


License

Licensed under the terms of the MIT License.

下载源码

通过命令行克隆项目:

git clone https://github.com/Kira-NT/HotAvalonia.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 HotAvalonia https://www.zuozi.net/31461.html

gemlikes
上一篇: gemlikes
php2python
下一篇: php2python
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务