0

I'm implementing the following source generator in a project of my solution:

[Generator]
public sealed class AvaloniaXamlSourceGeneraor : IIncrementalGenerator
{
    public void Initialize(IncrementalGeneratorInitializationContext context)
    {
        var axamlFiles = context.AdditionalTextsProvider
            .Where(static file => file.Path.EndsWith(".axaml", StringComparison.OrdinalIgnoreCase));

        var axamlFileContents = axamlFiles.Select((text, cancellationToken) =>
            (name: Path.GetFileNameWithoutExtension(text.Path), ContentDisposition: text.GetText(cancellationToken)!.ToString()));

        context.RegisterSourceOutput(
            axamlFileContents,
            static (context, compilation) =>
            {
                context.AddSource(compilation.name + ".gen.cs", $@"
class {compilation.name}__Gen {{ }}
");
            });
    }
}

I reference this project in another project of the solution that contains some .axaml files.

When I build the solution, the source generator is correctly executed and I can see the additional classes being compiled in the output assembly.

When I'm debugging the other project with Hot Reload enabled in Visual Studio, any change done to the C# code of the project triggers hot reload, but changes done to .axaml files don't call the source generator again. In fact, changing and saving a .axaml file during debug produces the following output in the Hot Reload section of the Output window:

08:45 29.85 Checking for updates...
08:45 30.12 No changes were found.

Is it possible to get source generators to run during hot reload?

0 Answers0