dotnet/wpf

WPF project build breaks because Roslyn Source Generators do not run in WPF inner-build

AArnott opened this issue ยท 5 comments

  1. Create a new WPF project.
  2. Add a PackageReference to any source generator.
  3. Add code to MainWindow.xaml.cs that depends on the generated code.
  4. Build

Expected

No build break

Actual

Build break.

In fact investigating the binary build log reveals that while the outer build's invocation of the Csc task provides the "analyzers" that are actually source generators:
image

The inner build invocation of Csc does not:
image

Thanks for reporting this, @AArnott.

Source generator support was added with #3846.

This is an opt-in feature. To use it, set the property IncludePackageReferencesDuringMarkupCompilation to true.

I'll follow-up when I find out which version of the .NET 5.0.xx SDK has the fix.

Would you consider making this on by default in 6.0 SDK's ?

@AArnott: I believe you validated with 5.0.102-servicing.20614.17. Can this be closed? Thanks.

Thanks.

It took me a while to find this issue, only after finding the comment in Microsoft.WinFX.targets.
My issue was not source generators, but a DiagnosticSuppressor from an Roslyn Analyzer nuget package.