Repository navigation
Fix temporary WPF assembly identity evaluation - #11995
amarinov-msft wants to merge 10 commits into
Conversation
Keep path properties and _TargetAssemblyProjectName available during props evaluation, then restore the evaluated AssemblyName and RootNamespace before SDK targets derive output identity. Co-authored-by: Copilot <[email protected]> Copilot-Session: b9298a94-6480-4b7c-b75d-4be15d13253f
Keep AssemblyName and RootNamespace available while the temporary project evaluates SDK props, then retain the late identity override. Use the first targets import as the fallback insertion anchor. Co-authored-by: Copilot <[email protected]> Copilot-Session: b9298a94-6480-4b7c-b75d-4be15d13253f
Use the first .targets import as the fallback insertion anchor without a redundant Sdk.targets special case. Co-authored-by: Copilot <[email protected]> Copilot-Session: b9298a94-6480-4b7c-b75d-4be15d13253f
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Explicit SDK imports can still cause identity restoration to occur too early or too late.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Addresses #5711 by restoring the original assembly identity during WPF temporary-project evaluation, before SDK targets derive output names.
Changes:
- Preserves properties needed before SDK props evaluation.
- Adds a late property group for
AssemblyNameandRootNamespace. - Adds import lookup to position identity restoration.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs | Separates early properties from late identity restoration and locates targets imports. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Prefer explicit SDK target imports when positioning the temporary identity properties. Split import groups at the SDK target import so the root-level identity group preserves import order and conditions. Co-authored-by: Copilot <[email protected]> Copilot-Session: b9298a94-6480-4b7c-b75d-4be15d13253f
Snapshot an ImportGroup condition before splitting it so imports before Sdk.targets cannot change whether the second half executes. Co-authored-by: Copilot <[email protected]> Copilot-Session: b9298a94-6480-4b7c-b75d-4be15d13253f
| continue; | ||
| } | ||
|
|
||
| if (string.Equals(element.Name, "Import", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
element.Name is a qualified name, if I understand correctly this would not work for project files with explicit namespace
There was a problem hiding this comment.
In practice Name and LocalName cannot differ here: MSBuild rejects prefixed elements, and this task only runs on projects MSBuild has already loaded. I switched the new checks to LocalName anyway for clarity. RemoveEntityByName uses the same .Name pattern and could get the same change in a separate PR.
Addressed in 53a06a8
| string project = import.GetAttribute("Project"); | ||
| return string.Equals(project, "Sdk.targets", StringComparison.OrdinalIgnoreCase) || | ||
| project.EndsWith(@"\Sdk.targets", StringComparison.OrdinalIgnoreCase) || | ||
| project.EndsWith("/Sdk.targets", StringComparison.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Slightly nervous about making a filename part of the contract, the build system does not really depend on filenames. Why is just checking the Sdk attribute not enough?
There was a problem hiding this comment.
Checking only the Sdk attribute would also match , which comes first. The properties would then go before Sdk.props, which is the scenario this PR is trying to fix. The file name is what tells the two apart, and it isn't ours: MSBuild hardcodes Sdk.props/Sdk.targets for implicit SDK imports (ProjectRootElement), and ReplaceImplicitImports already writes them. For the usual case this lookup isn't used. We insert before the node ReplaceImplicitImports creates. I've tightened it to an exact Sdk.targets match and added a comment.
Commit 091da63
| string condition = importGroup.GetAttribute("Condition"); | ||
| if (!string.IsNullOrEmpty(condition)) | ||
| { | ||
| string conditionPropertyName = "_WpfTempProjectImportGroupCondition_" + Guid.NewGuid().ToString("N"); |
There was a problem hiding this comment.
I think this whole block deserves some comment or example of what's going on and what it is trying to achieve
There was a problem hiding this comment.
Added an explanation comment with 3395233 with a before-and-after example explaining the split and why the condition is saved first. I also dropped the GUID suffix, since only one group is ever split and the generated project is the same on every build.
|
You mentioned this is a regression. Do we know what caused it? @ThomasGoulet73 mentioned in the past he had a working fix, want to review this one? |
|
@miloush Btw, I think the source generators are the only real way to solve this properly. |
Co-authored-by: Copilot <[email protected]> Copilot-Session: 43891a2e-162f-488b-ab67-0b34ea7aecaf
Yes. #3846 (5.0.2) added the source-generator-aware temp project path. Unlike the legacy path, which passes AssemblyName as a global property, it prepends |

Keep path properties and _TargetAssemblyProjectName available during props evaluation, then restore the evaluated AssemblyName and RootNamespace before SDK targets derive output identity.
Fixes #5711
Description
WPF markup compilation creates a temporary project when XAML references types from the same assembly. Although the evaluated
AssemblyNamewas copied into that project, it was placed beforeSdk.props. AnAssemblyNamedefined inDirectory.Build.propsor a<Choose>block could therefore be evaluated again using the temporary project name, causing markup compilation to fail with MC3074.This change keeps path properties and
_TargetAssemblyProjectNameavailable before props evaluation, while adding a separate late property group for the evaluatedAssemblyNameandRootNamespace. The identity group is inserted immediately before the generatedSdk.targetsimports, ensuringTargetNameand related properties are derived from the original project identity.The insertion logic supports multiple SDKs and projects without an implicit
Sdkattribute, without using a global property that could flow into referenced projects.Customer Impact
Affected WPF projects can build successfully without hard-coding
AssemblyNameor adding temporary-project-specific workarounds. The change applies only during temporary markup compilation and does not alter the final assembly's name or behavior of unaffected projects.Regression
Yes
Risk
Low. The change is limited to property placement in the temporary project used for WPF markup compilation. It preserves the existing early evaluation of path properties and
_TargetAssemblyProjectName, while restoring the already evaluatedAssemblyNameandRootNamespacebefore SDK targets derive output identity.Projects whose temporary assembly identity was already correct retain the same evaluated values. The change does not modify the final project’s assembly identity or pass
AssemblyNameas a global property to referenced projects.Microsoft Reviewers: Open in CodeFlow