From 8dad908ad15c01a5fdbbf85322a23c2ac9430ccf Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sat, 14 Nov 2026 18:36:35 -0600 Subject: [PATCH 1/3] Recompile ReadyToRun images when the crossgen2 arguments change _CreateR2RImages only compared files, so an incremental publish that changed only the crossgen2 arguments (for example PublishReadyToRunCrossgen2ExtraArgs) kept the stale images. Each batch now also outputs a state file named after a hash of the arguments. Outputs is expanded after the targets that run before _CreateR2RImages, so arguments they add to _PublishReadyToRunCrossgen2ExtraArgs are included. The state file is written after every batch compiles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../Microsoft.NET.CrossGen.targets | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index d25b30fbff4cdf..8576cbd194538e 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -499,12 +499,27 @@ Copyright (c) .NET Foundation. All rights reserved. _CreateR2RImages Compiles assemblies in the _ReadyToRunCompileList list into ReadyToRun images + + The compiler arguments are not files, so every batch also outputs a state file named after a hash of + them. When the arguments change, that file does not exist yet and every image is recompiled. + Outputs is expanded after the targets that run before this one, so the hash includes arguments + that they add. The body repeats the hash for _WriteReadyToRunCompilerArgumentsState; keep both in sync. ============================================================ --> + Outputs="%(_ReadyToRunCompileList.OutputR2RImage);%(_ReadyToRunCompileList.OutputPDBImage);$(_ReadyToRunOutputPath)/crossgen-args-$([MSBuild]::StableStringHash('$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs)|$(PublishReadyToRunComposite)|$(PublishReadyToRunContainerFormat)|$(PublishReadyToRunUseCrossgen2)|$(PublishReadyToRunPerfmapFormatVersion)', 'Sha256').Substring(0, 16)).stamp"> + + + <_ReadyToRunCompilerArgumentsStateFile>$(_ReadyToRunOutputPath)/crossgen-args-$([MSBuild]::StableStringHash('$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs)|$(PublishReadyToRunComposite)|$(PublishReadyToRunContainerFormat)|$(PublishReadyToRunUseCrossgen2)|$(PublishReadyToRunPerfmapFormatVersion)', 'Sha256').Substring(0, 16)).stamp + + + + <_StaleReadyToRunCompilerArgumentsStateFile Include="$(_ReadyToRunOutputPath)/crossgen-args-*.stamp" + Exclude="$(_ReadyToRunCompilerArgumentsStateFile)" /> + + + + + + + + + + - - + + - <_ReadyToRunCompilerArgumentsStateFile>$(_ReadyToRunOutputPath)/crossgen-args-$([MSBuild]::StableStringHash('$(PublishReadyToRunCrossgen2ExtraArgs);$(_PublishReadyToRunCrossgen2ExtraArgs)|$(PublishReadyToRunComposite)|$(PublishReadyToRunContainerFormat)|$(PublishReadyToRunUseCrossgen2)|$(PublishReadyToRunPerfmapFormatVersion)', 'Sha256').Substring(0, 16)).stamp + <_ReadyToRunCompilerArgumentsCacheFile>$(IntermediateOutputPath)$(MSBuildProjectName).ReadyToRunCompilerArguments.cache - + + + + + + + - <_StaleReadyToRunCompilerArgumentsStateFile Include="$(_ReadyToRunOutputPath)/crossgen-args-*.stamp" - Exclude="$(_ReadyToRunCompilerArgumentsStateFile)" /> + - + + + + - - - - - - - - - $(PublishReadyToRunCrossgen2ExtraArgs);--instruction-set:$(PublishReadyToRunInstructionSet) + + <_ReadyToRunInstructionSetArgs Condition="'$(PublishReadyToRunInstructionSet)' != ''">--instruction-set:$(PublishReadyToRunInstructionSet)