-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source Generators fail in WinUI 3 projects because Csc is invoked with AnalyzerConfigFiles #52306 #4744
Comments
Thanks @dotMorten, transferring this to WinUI to take the first stab |
Thanks for all the investigation!! :) @RealTommyKlein and @alwu-msft FYI |
Do we have any resolution for this? I am using 0.8 and still facing the same issue. |
One of the big advertised features of WinUI 3 was that is supports the latest .NET and would be able to use all the latest .NET 5 features, but source generators are a complete non-starter it seems. EDIT: this even applies to the WinUI Class Library template |
I guess the somewhat obvious workaround is to add the source generator reference to a class library, which you then reference from your WinUI project. For example my app has a class library called MyApp.CsWin32 which is basically empty except for the CsWin32 nuget reference. (Of course the generator needs to create public types in that case. To do that for CsWin32 you need to set |
I believe this was fixed with dotnet/msbuild#6438 - I can repro the issue on Visual Studio 16.9, but not 16.11.1. @agc93 are you still hitting this with Visual Studio 16.11.1? |
@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 |
Copied 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 microsoft/CsWin32#219 (comment)
Minimal repro solution
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 inMSBuild\Current\Bin\Microsoft.CSharp.CurrentVersion.targets
invokes theCsc
task but omitsAnalyzerConfigFiles
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
The text was updated successfully, but these errors were encountered: