Filter re-resolved analyzers from the WPF temporary project#11739
Filter re-resolved analyzers from the WPF temporary project#11739wnvko-msft wants to merge 2 commits into
Conversation
GenerateTemporaryTargetAssembly builds a temporary *_wpftmp project to resolve local types referenced from XAML. That temporary project re-runs analyzer resolution and re-adds package analyzers the parent project had intentionally removed, without honoring the packages' removal targets. In the Visual Studio in-process build this may reintroduces unnecessary analyzers and to fail. Tag the analyzers flowed from the parent project with pfTempProjectAnalyzers metadata and set _WpfTempProjectIncludesPackageReferences on the temporary project. A new FilterTemporaryAssemblyAnalyzers target then removes any analyzer lacking that marker, restoring the authoritative analyzer set the parent project already resolved. Fixes dotnet#9660
There was a problem hiding this comment.
Pull request overview
This PR fixes a Visual Studio in-process WPF publish/build failure where the generated *_wpftmp temporary project re-resolves NuGet analyzers/source generators (e.g., Microsoft.Extensions.Configuration.Binder’s C# 12 generator) and ends up with an incorrect analyzer set that can break the temporary compilation.
Changes:
- Stamp analyzer items flowed from the parent project with
WpfTempProjectAnalyzersmetadata when generating the temporary project. - Add a
_WpfTempProjectIncludesPackageReferencesmarker property to gate temp-project-only behavior. - Introduce an MSBuild target to remove analyzers in the temporary project that don’t have the parent-applied marker.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft/Build/Tasks/Windows/GenerateTemporaryTargetAssembly.cs | Tags flowed analyzer items and sets a marker property in the generated temp project. |
| src/Microsoft.DotNet.Wpf/src/PresentationBuildTasks/Microsoft.WinFX.targets | Adds FilterTemporaryAssemblyAnalyzers target to drop unmarked analyzers during temp project compilation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Verification: this fix resolves a family of related issuesI reproduced each of the issues below on a pristine SDK (no fix), then verified the same repro builds cleanly with this PR's change applied. All are the same root cause: in the
Each repro was a minimal WPF app: **.NET 9 note: ** #10553 is on .NET 9, whereas this PR targets Suggest closing #9660, #9589, #7624, #10175, and #10553 when this merges. |
Why re-running the duplicate-analyzer removal doesn't fix theseIt's a reasonable question: since the SDK already has
<FilteredAnalyzer Include="@(Analyzer->Distinct())" />
Same generator, two paths -> De-duping by file name / assembly identity instead is not a safe fix either:
This PR fixes the cause rather than the symptom: it marks the analyzers the parent project resolved ( |
Fixes #9660
Main PR
Description
When a XAML file references a locally defined type,
GenerateTemporaryTargetAssemblygenerates and builds a temporary*_wpftmpproject to resolve those types. That temporary project re-runs analyzer resolution (ResolveLockFileAnalyzers) and re-adds analyzers from NuGet packages, without importing those packages' build targets that would normally remove them. In the Visual Studio in-process build, this reintroduces theMicrosoft.Extensions.Configuration.Bindersource generator - which requires C#12 - into the temporary compilation, failing it withSYSLIB1102.This change tags every analyzer flowed from the parent project with
WpfTempProjectAnalyzersmetadata and sets a_WpfTempProjectIncludesPackageReferencesmarker property on the temporary project. A newFilterTemporaryAssemblyAnalyzerstarget (running only inside that temporary project, afterRemoveDuplicateAnalyzersand beforeCoreCompile) then removes any analyzer lacking the marker, restoring the authoritative analyzer set the parent project already resolved.Customer Impact
WPF customers cannot publish (or, in some cases, build) self-contained apps from Visual Studio when they reference
Microsoft.Extensions.Configuration.Binder(8.0.x) and use config binding such asconfig.Get<T>(). Publish fails with a generic "Publish has encountered an error" backed bySYSLIB1102. There is no straightforward workaround other than avoiding the package or forcingLangVersion, both undesirable.Regression
Yes - this regressed for customers when the
Microsoft.Extensions.Configuration.Binderpackage introduced its C#12 source generator (.NET 8 timeframe), combined with the Visual Studio 17.10 in-process build pipeline. It does not reproduce viadotnet build / publishfrom the command line, only through the Visual Studio in-process Publish path.Testing
Microsoft.Extensions.Configuration.Binder8.0.2 with a local type referenced in XAML, published self-contained from Visual Studio 17.10 (SDK 8.0.401) - failed withSYSLIB1102in the*_wpftmpcompilation.PresentationBuildTasksfrom the corresponding release branch with this fix, staged it plus the updated targets into the local SDK, and re-ran the same Visual Studio Publish - succeeds,SYSLIB1102is gone._WpfTempProjectIncludesPackageReferences, which is set only in the package-reference temporary-build path, so normal (non-temp) builds and the legacy markup-compilation path are unaffected.Risk
Low. The behavior change is scoped tightly:
_WpfTempProjectIncludesPackageReferencesproperty), so it cannot affect normal builds or the legacy path.Microsoft Reviewers: Open in CodeFlow