Skip to content

Conversation

qiutongMS
Copy link
Contributor

This change addresses MSBuild warning MSB8027 that occurs when multiple targets in BeforeClCompileTargets modify the same parameter.

Technical Details:

  1. Semantic Equivalence: PreprocessorDefinitions and AdditionalOptions are semantically equivalent for defining preprocessor macros. Both /D MACRO_NAME (AdditionalOptions) and MACRO_NAME;%(PreprocessorDefinitions) achieve the same compilation result.

  2. Root Cause: When two targets in BeforeClCompileTargets both modify the same parameter (e.g., PreprocessorDefinitions), the second target to execute may cause duplicate entries to be added to the cl compile command due to parameter modification conflicts.

  3. Solution: By using different but equivalent parameters (PreprocessorDefinitions vs AdditionalOptions), we can avoid this MSBuild parameter collision issue while maintaining the same functionality.

Scope:

This commit specifically addresses the Bootstrap target. The GenerateUndockedRegFreeWinRTCpp target has the same underlying issue, but modifications to it cause arm64EC build failures in WinUI projects. Further investigation is needed before addressing that target, so this change is submitted as an incremental fix for the Bootstrap scenario.

Testing: This change has been tested to ensure no functional regression while eliminating the MSBuild warning.

A microsoft employee must use /azp run to validate using the pipelines below.

WARNING:
Comments made by azure-pipelines bot maybe inaccurate.
Please see pipeline link to verify that the build is being ran.

For status checks on the main branch, please use TransportPackage-Foundation-PR
(https://microsoft.visualstudio.com/ProjectReunion/_build?definitionId=81063&_a=summary)
and run the build against your PR branch with the default parameters.

@qiutongMS
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiutongMS qiutongMS requested review from codendone and ssparach and removed request for ssparach September 2, 2025 07:25
@Scottj1s
Copy link
Member

Scottj1s commented Sep 3, 2025

I'm not confident this is a complete fix. It's important to understand why modifying PreprocessorDefinitions causes this warning. It's due to MSBuild batching behavior. Any time "%" metadata is referenced in a target or task, that target/task is executed for each distinct batch defined by that metadata. This could occur as easily with AdditionalOptions. My recommendation was to ensure that any dynamic preprocessor definitions be applied after all sources had been added. This will prevent batching and the subsequent warning.

Copy link
Member

@Scottj1s Scottj1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider strategy of applying any metadata changes after all sources have been included, to prevent batching.

@chwarr
Copy link
Member

chwarr commented Sep 3, 2025

In the proposed change, the ClCompile item is added inside a target. It doesn't look like any target logic is being used here, so another way to fix this might be to add the ClCompile item outside a target. Then, the batching multiplicative behavior won't kick in.

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

Successfully merging this pull request may close these issues.

3 participants