Skip to content
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

Closed
dotMorten opened this issue Apr 2, 2021 · 7 comments
Labels
area-External Not owned by the WinUI team, not actionable in this repository. area-Tooling product-winui3 WinUI 3 issues team-Markup Issue for the Markup team v0.5 Issues introduced in the Project Reunion 0.5 prerelease

Comments

@dotMorten
Copy link
Contributor

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
image
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
image

XamlPreCompile target's invocation of Csc:
image
image

@andrewleader
Copy link

Thanks @dotMorten, transferring this to WinUI to take the first stab

@andrewleader andrewleader transferred this issue from microsoft/WindowsAppSDK Apr 5, 2021
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Apr 5, 2021
@StephenLPeters
Copy link
Contributor

Thanks for all the investigation!! :) @RealTommyKlein and @alwu-msft FYI

@StephenLPeters StephenLPeters added area-Tooling v0.5 Issues introduced in the Project Reunion 0.5 prerelease team-Markup Issue for the Markup team product-winui3 WinUI 3 issues labels Apr 6, 2021
@abhi-msft
Copy link

Do we have any resolution for this? I am using 0.8 and still facing the same issue.

@agc93
Copy link

agc93 commented Aug 22, 2021

Is there any update or workaround for this? This seems to be fixed in v16.11.1

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

@Marv51
Copy link
Contributor

Marv51 commented Aug 23, 2021

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 "public": true in your NativeMethods.json.

@RealTommyKlein
Copy link
Contributor

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?

@agc93
Copy link

agc93 commented Aug 23, 2021

@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

@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Dec 6, 2022
@evelynwu-msft evelynwu-msft added the area-External Not owned by the WinUI team, not actionable in this repository. label Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-External Not owned by the WinUI team, not actionable in this repository. area-Tooling product-winui3 WinUI 3 issues team-Markup Issue for the Markup team v0.5 Issues introduced in the Project Reunion 0.5 prerelease
Projects
None yet
Development

No branches or pull requests

9 participants