Add workarounds and documentation for NativeAOT _BUILDCONFIG duplicate key error #65925
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NativeAOT scenario runs in Azure DevOps fail with
An item with the same key has already been added. Key: _BUILDCONFIGduring MSBuild's out-of-process task host environment synchronization. The error occurs when environment variables are set at multiple levels (system, agent, pipeline), causing dictionary insertion to fail inOutOfProcTaskHostNode.UpdateEnvironmentForMainNode().Workaround Script
workarounds/nativeaot-environment-fix.sh- Detects Azure DevOps environments and appliesMSBuildTaskHostDoNotUpdateEnvironment=1to bypass environment syncTF_BUILD/AGENT_IDor presence of build config variablesDocumentation
TROUBLESHOOTING.md- Root cause analysis, 4 workaround options, debugging techniquesworkarounds/azure-pipelines-example.yml- 4 pipeline integration patterns.github/ISSUE_TEMPLATE/build-failure.md- Structured issue reporting templateUsage
Pipeline-level fix (recommended):
Or use detection script:
This is a workaround-only solution. The underlying MSBuild issue should be fixed upstream to handle duplicate environment variable keys gracefully.
Original prompt
We have started hitting the following error in our main branch nativeaot_scenarios runs that run in Azure Devops.