Skip to content

Only disable StartupHookSupport in non-Debug builds; remove MetadataUpdaterSupport from ILLink.targets#126546

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/set-startuphooksupport-to-true
Draft

Only disable StartupHookSupport in non-Debug builds; remove MetadataUpdaterSupport from ILLink.targets#126546
Copilot wants to merge 4 commits intomainfrom
copilot/set-startuphooksupport-to-true

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

Microsoft.NET.ILLink.targets was unconditionally disabling StartupHookSupport and MetadataUpdaterSupport for all trimmed/AOT builds, blocking Hot Reload in Debug AOT apps and overriding the SDK's correct per-configuration handling of MetadataUpdaterSupport.

Description

  • Microsoft.NET.ILLink.targets
    • StartupHookSupport: added and '$(Configuration)' != 'Debug' to the condition — startup hooks (and thus Hot Reload) are preserved in Debug builds
    • MetadataUpdaterSupport: removed entirely — the SDK (Microsoft.NET.Sdk.targets) already sets this to false for non-Debug builds; ILLink.targets was erroneously overriding that in Debug
<!-- Before -->
<StartupHookSupport Condition="'$(StartupHookSupport)' == ''">false</StartupHookSupport>
<MetadataUpdaterSupport Condition="'$(MetadataUpdaterSupport)' == ''">false</MetadataUpdaterSupport>

<!-- After -->
<StartupHookSupport Condition="'$(StartupHookSupport)' == '' and '$(Configuration)' != 'Debug'">false</StartupHookSupport>

No test changes are included — per reviewer guidance, this kind of MSBuild targets testing is done in the SDK repo.

…taUpdaterSupport from ILLink.targets; add tests

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/64db1ca8-95d8-47be-90ab-be736ed09ab0

Co-authored-by: tmat <41759+tmat@users.noreply.github.com>
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Apr 4, 2026
Copilot AI changed the title [WIP] Update Microsoft.NET.ILLink.targets to enable StartupHookSupport in debug builds Only disable StartupHookSupport in non-Debug builds; remove MetadataUpdaterSupport from ILLink.targets Apr 4, 2026
Copilot finished work on behalf of tmat April 4, 2026 17:24
Copilot AI requested a review from tmat April 4, 2026 17:24
@jkotas jkotas added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed area-Infrastructure-libraries labels Apr 6, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Copy Markdown
Member

If we do this change, there will be a warning when publishing debug:

D:\>dotnet new console -o starthook
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring D:\starthook\starthook.csproj:
Restore succeeded.



D:\>cd starthook

D:\starthook>dotnet publish -c Debug -p:PublishTrimmed=true -p:StartupHookSupport=true
Restore complete (1.2s)
  starthook net10.0 win-x64 succeeded with 1 warning(s) (4.9s) → bin\Debug\net10.0\win-x64\publish\
    ILLink : Trim analysis warning IL2026: System.StartupHookProvider.ProcessStartupHooks(String): Using member 'System.StartupHookProvider.CallStartupHook(StartupHookProvider.StartupHookNameOrPath)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The StartupHookSupport feature switch has been enabled for this app which is being trimmed. Startup hook code is not observable by the trimmer and so required assemblies, types and members may be removed.

Build succeeded with 1 warning(s) in 6.4s

Are we okay with that?

These are the intentional warnings that we put in place so that people are warned the feature will not work.

We could suppress the intentional warning in Corelib, but that breaks the promise that no warnings means the app will work the same with or without trimming.

I really wonder whether we should just introduce a private mechanism for this that corelib can check for in addition to StartupHookSupport and do something so we can still trim this when publishing.

Cc @dotnet/illink

Copilot AI requested review from Copilot and removed request for Copilot April 6, 2026 15:28
Copilot finished work on behalf of tmat April 6, 2026 15:30
@tmat
Copy link
Copy Markdown
Member

tmat commented Apr 6, 2026

@MichalStrehovsky We discussed options in #123778. Specifically comments #123778 (comment) and #123778 (comment).

What about updating runtimeconfig.json when it's being published to "System.Reflection.Metadata.MetadataUpdater.IsSupported": false?

Actually, I just found that there is a concept of .runtimeconfig.dev.json. It seems like that's what we want. Set "System.Reflection.Metadata.MetadataUpdater.IsSupported": true in .runtimeconfig.dev.json and "System.Reflection.Metadata.MetadataUpdater.IsSupported": false in .runtimeconfig.json, assuming that .dev takes precedence if present.

Unfortunately, it looks like configurationProperties specified in .runtimeconfig.json overwrite those in .runtimeconfig.dev.json:

m_properties[property.name.GetString()] = property.value.GetString();

@agocke is that intentional? It would make more sense the other way around.

@MichalStrehovsky
Copy link
Copy Markdown
Member

@MichalStrehovsky We discussed options in #123778. Specifically comments #123778 (comment) and #123778 (comment).

I saw that, but I didn't see the warnings discussed. Warnings like this are problematic because it's a bad UX and people love to do WarningsAsErrors, then forget they set it and never think about it again, and get completely blocked by a relatively harmless warning.

It feels like what we need is to make this line conditional somehow:

https://github.com/dotnet/sdk/blob/61c38b063559ae55bf6d312ad9a5940aa5d5a0ea/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L708-L711

Would BuildingInsideVisualStudio property work (would it be set when doing publish in the VS UI)? Would we need something else for dotnet watch?

@tmat
Copy link
Copy Markdown
Member

tmat commented Apr 6, 2026

Would BuildingInsideVisualStudio property work (would it be set when doing publish in the VS UI)? Would we need something else for dotnet watch?

No, we don't want to use any such property. BuildingInsideVisualStudio is a hack that shouldn't even exist. I think the right solution is to use runtimeconfig.dev.json as described above and fix how properties in runtimeconfig(.dev).json are overridden.

@tmat
Copy link
Copy Markdown
Member

tmat commented Apr 7, 2026

Filed #126606

@agocke
Copy link
Copy Markdown
Member

agocke commented Apr 9, 2026

@elinor-fung for runtimeconfig/runtimeconfig.dev.json question

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

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set StartupHookSupport to true in Debug builds when PublishAOT is true

5 participants