question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Source Generators fail in WinUI 3 projects because Csc is invoked with AnalyzerConfigFiles #52306

See original GitHub issue

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 https://github.com/microsoft/CsWin32/issues/219#issuecomment-811272354

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewleadercommented, Apr 5, 2021

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

0reactions
agc93commented, Aug 25, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source Generators fail in WinUI 3 projects because Csc is ...
A project reunion project fails to build when it contains code that relies on a Source Generator in any of the XAML code-behind...
Read more >
c# - Source generator with physical files on disk causing ...
I'm facing two issues now with my project, first is whenever I try to deserialize the json file (additional file) to my own...
Read more >
Source Generators
Source Generators is a C# compiler feature that lets C# developers inspect user code as it is being compiled. Source generators create new ......
Read more >
Incremental Roslyn Source Generators In .NET 6
Creation of a New Incremental Source Generator. In this article, we want to create a simple Incremental Source Generator for generating so-called Smart...
Read more >
Let's Build an Incremental Source Generator With Roslyn, by ...
While source generators (compatible with the .NET 5 SDK) potentially cause a sluggish developer experience in huge projects and solutions, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found