Skip to content

Enable Hot Reload on CoreCLR for Android#11239

Closed
kotlarmilos wants to merge 1 commit intodotnet:mainfrom
kotlarmilos:coreclr-android-hr-env
Closed

Enable Hot Reload on CoreCLR for Android#11239
kotlarmilos wants to merge 1 commit intodotnet:mainfrom
kotlarmilos:coreclr-android-hr-env

Conversation

@kotlarmilos
Copy link
Copy Markdown
Member

@kotlarmilos kotlarmilos commented Apr 28, 2026

Description

This PR routes the Hot Reload settings through runtimeconfig.json configProperties so they reach CoreCLR at host init on Android. In Microsoft.Android.Sdk.HotReload.targets the STARTUP_HOOKS RuntimeHostConfigurationOption is no longer gated on UseMonoRuntime=true, and for CoreCLR debug builds two additional options are emitted: ModifiableAssemblies=debug and System.Reflection.Metadata.MetadataUpdater.IsSupported=true. Today these settings only reach Mono via __environment__.txt, which libmonodroid.so consumes before runtime init; CoreCLR's PAL snapshots the OS environment at startup and never reads that file, so the existing Mono path was a no-op for CoreCLR. The Mono path is unchanged.

With this PR, end-to-end dotnet watch Hot Reload works on the Android emulator with RuntimeFlavor=CoreCLR.

Route the Hot Reload settings through runtimeconfig.json configProperties
so they reach CoreCLR at host init on Android. In
Microsoft.Android.Sdk.HotReload.targets the STARTUP_HOOKS
RuntimeHostConfigurationOption is no longer gated on
UseMonoRuntime=true, and for CoreCLR debug builds two additional options
are emitted: ModifiableAssemblies=debug and
System.Reflection.Metadata.MetadataUpdater.IsSupported=true.

Today these settings only reach Mono via __environment__.txt, which
libmonodroid.so consumes before runtime init; CoreCLR's PAL snapshots
the OS environment at startup and never reads that file, so the
existing Mono path was a no-op for CoreCLR. The Mono path is unchanged.

With this change, end-to-end dotnet watch Hot Reload works on the
Android emulator with RuntimeFlavor=CoreCLR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 28, 2026 17:41
@kotlarmilos kotlarmilos added this to the .NET 11 milestone Apr 28, 2026
@kotlarmilos kotlarmilos self-assigned this Apr 28, 2026
@kotlarmilos kotlarmilos marked this pull request as draft April 28, 2026 17:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables Hot Reload for Android apps running on CoreCLR by flowing dotnet-watch Hot Reload settings through runtimeconfig.json configProperties, ensuring CoreCLR receives them at host initialization (unlike the existing __environment__.txt path which CoreCLR doesn’t consume).

Changes:

  • Emit STARTUP_HOOKS via RuntimeHostConfigurationOption for both MonoVM and CoreCLR so the Hot Reload agent is discoverable from runtimeconfig.json.
  • For CoreCLR debug-symbol builds, also emit ModifiableAssemblies=debug and System.Reflection.Metadata.MetadataUpdater.IsSupported=true via runtimeconfig.
  • Update inline documentation/comments in Microsoft.Android.Sdk.HotReload.targets to reflect the CoreCLR behavior.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.HotReload.targets Routes Hot Reload startup hooks and CoreCLR modifiable-assemblies settings through runtimeconfig so CoreCLR can pick them up at host init.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines +66 to +70
which is required on Android where the DOTNET_STARTUP_HOOKS env var written
to __environment__.txt is only consumed by Mono via libmonodroid.so;
CoreCLR's PAL snapshots the OS environment at startup and never reads it.
-->
<RuntimeHostConfigurationOption Include="STARTUP_HOOKS" Value="$(_AndroidHotReloadAgentAssemblyName)" />
@kotlarmilos
Copy link
Copy Markdown
Member Author

Closing this in favor of #11240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants