Skip to content

Commit 1c1d352

Browse files
committed
fix: metadata update after XAML hot reload breaks compilation
1 parent 65e32f5 commit 1c1d352

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/SourceGenerators/Uno.UI.SourceGenerators/Content/Uno.UI.SourceGenerators.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<CompilerVisibleProperty Include="BuildingProject" />
4343
<CompilerVisibleProperty Include="DesignTimeBuild" />
4444
<CompilerVisibleProperty Include="UnoUISourceGeneratorDebuggerBreak" />
45+
<CompilerVisibleProperty Include="IsHotReloadHost" />
4546

4647
<CompilerVisibleProperty Include="UseWPF" />
4748
<CompilerVisibleProperty Include="IsUnoHead" />

src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/GenerationInfoManager.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ internal void Update(GeneratorExecutionContext context)
5656
}
5757
}
5858

59-
if(bool.TryParse(context.GetMSBuildPropertyValue("DesignTimeBuild"), out var designTimeBuild) && designTimeBuild)
59+
if(GetIsDesignTimeBuild(context) && !GetIsHotReloadHost(context))
6060
{
61+
// Design-time builds need to clear runs for the x:Name values to be regenerated, in the context of OmniSharp.
62+
// In the context of HotReload, we need to skip this, as the HotReload service sets DesignTimeBuild to build
63+
// to true, preventing existing runs to be kept active.
6164
_runs.Clear();
6265
}
6366
}
67+
68+
private bool GetIsDesignTimeBuild(GeneratorExecutionContext context)
69+
{
70+
return bool.TryParse(context.GetMSBuildPropertyValue("DesignTimeBuild"), out var value) && value;
71+
}
72+
73+
private bool GetIsHotReloadHost(GeneratorExecutionContext context)
74+
{
75+
return bool.TryParse(context.GetMSBuildPropertyValue("IsHotReloadHost"), out var value) && value;
76+
}
6477
}
6578
}

src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Initialize(GeneratorInitializationContext context)
3131
public void Execute(GeneratorExecutionContext context)
3232
{
3333
// No initialization required for this one
34-
//if (!Process.GetCurrentProcess().ProcessName.Equals("devenv", StringComparison.OrdinalIgnoreCase))
34+
//if (!Process.GetCurrentProcess().ProcessName.Equals("omnisharp.exe", StringComparison.OrdinalIgnoreCase))
3535
//{
3636
// Debugger.Launch();
3737
//}

src/Uno.UI.RemoteControl.Server.Processors/HotReload/MetadataUpdates/CompilationWorkspaceProvider.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static async void CreateProject(
4040
// Override the output path so custom compilation lists do not override the
4141
// main compilation caches, which can invalidate incremental compilation.
4242
{ "IntermediateOutputPath", intermediatePath },
43+
44+
// Mark this compilation as hot-reload capable, so generators can act accordingly
45+
{ "IsHotReloadHost", "True" },
4346
};
4447

4548
var workspace = MSBuildWorkspace.Create(globalProperties);

0 commit comments

Comments
 (0)