Compose DOTNET_STARTUP_HOOKS across all Android environment sources instead of overwriting#11187
Compose DOTNET_STARTUP_HOOKS across all Android environment sources instead of overwriting#11187
DOTNET_STARTUP_HOOKS across all Android environment sources instead of overwriting#11187Conversation
Agent-Logs-Url: https://github.com/dotnet/android/sessions/a0bba47d-8a89-476b-b420-c6c5e6914563 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/android/sessions/a0bba47d-8a89-476b-b420-c6c5e6914563 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
DOTNET_STARTUP_HOOKS across all Android environment sources instead of overwriting
simonrozsival
left a comment
There was a problem hiding this comment.
@copilot address my questions
| </Target> | ||
|
|
||
| <Target Name="_GenerateEnvironmentFiles" DependsOnTargets="_AndroidConfigureHotReloadEnvironment"> | ||
| <Target Name="_ComposeDotNetStartupHooks" |
There was a problem hiding this comment.
This target does not have Inputs and Outputs, should it have them?
There was a problem hiding this comment.
Good question. I kept _ComposeDotNetStartupHooks without Inputs/Outputs intentionally because it only transforms in-memory MSBuild items/properties for the current build graph; persisting incremental state there could skip needed recomposition. I also moved the final cross-file merge to EnvironmentBuilder in 120aedf, so this target stays lightweight and order-safe.
| <ReadLinesFromFile File="%(_AndroidEnvironmentStartupHookFiles.Identity)"> | ||
| <Output TaskParameter="Lines" ItemName="_AndroidEnvironmentStartupHookLines" /> | ||
| </ReadLinesFromFile> |
There was a problem hiding this comment.
If I understand it correctly, we will leave the original DOTNET_STARTUP_HOOKS values in the env files? Doesn't this mean that we will have multiple definitions of DOTNET_STARTUP_HOOKS in the final list of environment variables? Shouldn't we move the merging logic to the GenerateAdditionalProviderSources or EnvironmentBuilder or some other place where we eventually merge all the environment variables into a single list of definitions?
There was a problem hiding this comment.
You're right. I changed this in 120aedf: _ComposeDotNetStartupHooks no longer reads @(AndroidEnvironment)/@(LibraryEnvironments) lines, and EnvironmentBuilder now merges repeated DOTNET_STARTUP_HOOKS definitions while parsing the final environment inputs. This moves merging to the consolidation point and avoids duplicate final definitions.
Agent-Logs-Url: https://github.com/dotnet/android/sessions/eaf7b02c-a819-4e2f-8bd5-fedfee6f1931 Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
Addressed in 120aedf. I answered both review questions and updated the implementation so final |
DOTNET_STARTUP_HOOKSwas being rewritten by Hot Reload/trimmable typemap targets from@(RuntimeEnvironmentVariable)only, which silently dropped values provided via@(AndroidEnvironment)files. This change now composes startup hooks in two layers: contribution in targets, and final merge at environment consolidation time.Compose target-level startup-hook contributions before environment file generation
_ComposeDotNetStartupHooksinXamarin.Android.Common.targets(wired before_GenerateEnvironmentFiles).@(_AndroidDotnetStartupHooks)@(RuntimeEnvironmentVariable)entries forDOTNET_STARTUP_HOOKSRuntimeEnvironmentVariablevalue joined with:.Merge repeated
DOTNET_STARTUP_HOOKSdefinitions at the final consolidation layerEnvironmentBuilderto merge repeatedDOTNET_STARTUP_HOOKSvalues (from environment files and generated entries) instead of last-write-wins.DOTNET_STARTUP_HOOKSvalue.Stop Hot Reload from mutating
@(RuntimeEnvironmentVariable)directly_AndroidConfigureHotReloadEnvironmentnow contributes the normalized assembly name to@(_AndroidDotnetStartupHooks)instead of remove/re-add onDOTNET_STARTUP_HOOKS.RuntimeHostConfigurationOptionbehavior unchanged.Add focused coverage for cross-source merge behavior
EnvironmentContentTeststhat defines:RuntimeEnvironmentVariable)AndroidEnvironment)DOTNET_STARTUP_HOOKScontains both values.