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 |
jonathanpeppers
left a comment
There was a problem hiding this comment.
@copilot can you simplify the changes here?
- Use the
@(_AndroidDotnetStartupHooks)item group throughout, pass it into the task that writes environment variables - Clear startup hooks from
@(RuntimeEnvironmentVariable), and rely on@(_AndroidDotnetStartupHooks) - The task that writes environment variables merges
@(_AndroidDotnetStartupHooks)and any found from@(AndroidEnvironment)files
Agent-Logs-Url: https://github.com/dotnet/android/sessions/f4947bfc-48c4-4b7a-ab89-4760d3d73354 Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/android/sessions/f4947bfc-48c4-4b7a-ab89-4760d3d73354 Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Done in 56b9467 (building on 22ec383). I simplified the flow to keep startup hooks in |
DOTNET_STARTUP_HOOKSwas being rewritten from@(RuntimeEnvironmentVariable)only, which could drop values coming from@(AndroidEnvironment)files. This change keeps startup hook composition explicit and ensures final environment generation merges all sources without duplicate-effective definitions.Use a single startup-hook item flow
_ComposeDotNetStartupHooksinXamarin.Android.Common.targetsnow builds@(_AndroidDotnetStartupHooksDistinct)from:@(_AndroidDotnetStartupHooks)@(RuntimeEnvironmentVariable)entries forDOTNET_STARTUP_HOOKSDOTNET_STARTUP_HOOKSis removed from@(RuntimeEnvironmentVariable)and startup hooks are carried via@(_AndroidDotnetStartupHooksDistinct).Generate environment file from composed hooks
_GenerateEnvironmentFileswritesDOTNET_STARTUP_HOOKS=...from@(_AndroidDotnetStartupHooksDistinct, ':')into__environment__.txt.Pass startup hooks into environment-producing tasks
DotNetStartupHookstask input and wired it from@(_AndroidDotnetStartupHooksDistinct)for:GenerateNativeApplicationConfigSourcesGenerateAdditionalProviderSourcesGenerateNativeAotEnvironmentAssemblerSourcesMerge at consolidation point
EnvironmentBuildernow accepts explicit startup hooks viaAddDotNetStartupHooks(...).DOTNET_STARTUP_HOOKSfound while parsing@(AndroidEnvironment)/@(LibraryEnvironments)using colon-separated dedupe.Hot Reload behavior remains compatible
_AndroidConfigureHotReloadEnvironmentcontinues contributing normalized startup hook assembly names to@(_AndroidDotnetStartupHooks)and keepsRuntimeHostConfigurationOptionbehavior unchanged.Focused test coverage
EnvironmentContentTestsverifies finalDOTNET_STARTUP_HOOKScontains values from bothRuntimeEnvironmentVariableandAndroidEnvironment.