Exclude _wpftmp temp project from design-time markup compilation#11778
Open
anagnorisis2peripeteia wants to merge 1 commit into
Open
Exclude _wpftmp temp project from design-time markup compilation#11778anagnorisis2peripeteia wants to merge 1 commit into
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
The temporary *_wpftmp markup-compile project generated by
GenerateTemporaryTargetAssembly exists only to compile the already-generated
code-behind, which it lists explicitly. Under the .NET 10 SDK,
CoreCompileDependsOn now runs DesignTimeMarkupCompilation for command-line
design-time builds ('$(DesignTimeBuild)' == 'true'), and this also fires inside
the _wpftmp project, adding the generated *.g.cs a second time and tripping
NETSDK1022 (Duplicate 'Compile' items).
Exclude _wpftmp projects from the design-time markup-compilation dependency so
the generated files are listed exactly once. Real projects are unaffected and
SDK 8 behavior is unchanged.
Fixes dotnet#11775.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Under the .NET 10 SDK, a command-line design-time build (
-p:DesignTimeBuild=true) of a WPF project that defines a local or internal XAML type fails withNETSDK1022: Duplicate 'Compile' items. This breaks tooling that drives design-time builds (analysis, mutation testing via Stryker.NET/Buildalyzer), and is a regression from the .NET 8 SDK, where the same project builds cleanly.Fixes #11775.
Root cause
Microsoft.WinFX.targetsaddsDesignTimeMarkupCompilationtoCoreCompileDependsOnwhen$(BuildingInsideVisualStudio)or$(DesignTimeBuild)is true (the$(DesignTimeBuild)arm was added so command-line design-time builds also surface the generated code).WPF resolves references to local/internal XAML types by generating a temporary
*_wpftmpproject (viaGenerateTemporaryTargetAssembly) and compiling it; that temporary project already lists the generated code-behind (*.g.cs) explicitly. Because the temporary project inherits the same targets, the new$(DesignTimeBuild)arm now also runsDesignTimeMarkupCompilationinside the temporary project, which adds the same generated files a second time — producing the duplicateCompileitems.Evaluating the temporary project standalone shows each generated file exactly once (the SDK's default glob correctly excludes
obj\); the second copy is added at build time only, by the markup compilation running inside the temp project. Reverting just the$(DesignTimeBuild)arm makes the build succeed; reverting the other condition changed in the same file has no effect.Fix
Exclude the temporary
*_wpftmpproject from the design-time markup-compilation dependency. It exists solely to compile already-generated code (which it lists explicitly), so it never needed to run markup compilation itself.Testing — real-behavior before/after proof
Proof mode:
before_after. Repro: a WPF class library defining a local XAML type, built with theidentical command on SDK 10.0.301, with only the one-line targets change differing between runs:
Before (base
Microsoft.WinFX.targets) — FAILS:After (this change) — SUCCEEDS:
LocalControl.g.cs,GeneratedInternalTypeHelper.g.cs)Not a false pass: with the fix the real project still performs markup compilation —
LocalControl.g.csis generated and the temporary
_wpftmpproject is still created — only the redundant re-compilationinside
_wpftmpis suppressed. The same project builds cleanly on SDK 8.0.420 (unchanged) and nowon SDK 10.0.301. Both sides were captured back-to-back in one run on the same SDK, reverting the
targets file (SHA-256-verified) between them, so the two builds differ only by this one committed line.
Customer Impact
Command-line design-time builds of WPF projects with local/internal XAML types fail on the .NET 10 SDK, breaking tooling that relies on them. Interactive (VS) builds are unaffected. Restores .NET 8 behavior.
Regression?
Yes — regression from the .NET 8 SDK, surfaced by the
$(DesignTimeBuild)addition toCoreCompileDependsOn.Risk
Low. One-line condition change scoped to the internally-generated
*_wpftmpproject; real projects and the VS/IDE path are unaffected, and the excluded markup compilation was redundant for that project (its generated files are already listed explicitly).Review history (before/after proof + review dispositions): https://gist.github.com/anagnorisis2peripeteia/9d7b6ef4c25e6e3d706529f916a2f4f7
Microsoft Reviewers: Open in CodeFlow