Source Generators fail in WinUI 3 projects because Csc is invoked with AnalyzerConfigFiles #52306
See original GitHub issueCopied from https://github.com/dotnet/roslyn/issues/52306. See follow-up comments in that issue where it is indicated this would be a better place to put it. (Or maybe not?)
Describe the bug
A project reunion project fails to build when it contains code that relies on a Source Generator in any of the XAML code-behind files.
Steps to reproduce the bug
(based on @dotMorten’s report https://github.com/microsoft/CsWin32/issues/219#issuecomment-811272354
Or manual steps:
Install Project Reunion Project Templates: https://marketplace.visualstudio.com/items?itemName=ProjectReunion.MicrosoftProjectReunion Create a new Blank App, Packaged (WinUI 3 in Desktop) project. Install the Microsoft.Windows.CsWin32 nuget package (0.1.422-beta) Add NativeMethods.txt and some interop methods to it. Open MainWindow.xaml.cs, and in the constructor add a pinvoke method call. Compile Observe errors in the error list Using VS16.10.p1
Expected behavior
The build is successful.
Analysis
Examining the build log I’ve found the problem:
The XamlPreCompile
target as defined in MSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets
invokes the Csc
task but omits AnalyzerConfigFiles
that is normally passed in. As a result, the CsWin32 source generator is not getting the info it needs to generate the APIs referenced in the XAML code-behind.
Screenshots
The CoreCompile
target’s invocation of Csc:
image
XamlPreCompile
target’s invocation of Csc:
image
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top GitHub Comments
Thanks @dotMorten, transferring this to WinUI to take the first stab
@RealTommyKlein I am still running into it but I’m on 16.11.0 Preview 3. I’ll try again with the non-Preview bits.
EDIT: you’re right that v16.11.1 non-Preview worked fine for me so maybe I was just missing an update