-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 Generator support for WPF project blocked? #3404
Comments
The issue is that the WPF intermediate build clears the analyzers collection as a way of disabling analyzers from running. This obviously wipes out the generators too, so we need to update the WPF targets to use the new 'SkipAnalyzers' option instead. See: dotnet/roslyn#46669 I think there is an issue for this WPF + generators problem somewhere already, but can't find it right now. |
Please consider documenting the lack of WPF support somewhere, because it "just doesn't work" but without any error. It took me quite a while to figure out what was the issue here and even in hindsight I couldn't find any warning. |
Transferring this issue to the wpf repository as it appears they are not properly passing |
This would be a blocking issue for adoption since it makes either source generators or WPF unusable. Just documenting that it doesn't work isn't enough, this needs to be implemented. For example the new COM interop story (CsWinRT) is already looking at using source generators to dynamically generate code, so the amount of things WPF would be incompatible with is only rapidly going to grow from here as generators are adopted by other nuget packages. |
Intent is to fix the behavior, not document it. |
What info is needed @ryalanms? (Also, when I was asking for documentation I meant to add a known-issue that it is not working in the previews, while it is being worked on.) |
@Marv51 from another issue
|
I believe this is a dup of #810 which I think is the same underlying issue. If not a dup, would be impacted by any source generators that ship as a NuGet package. |
Not a direct dup, note that OP is using |
CC @dotnet/dotnet-wpf as they will need to decide when this fits into their schedule |
I found a hint on how to solve the problem here #3974 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
...
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
...
</PropertyGroup> In my case it works. |
Thanks for pointing this out, @Zalutskii. Existing source generator and PackageReference issues have not been linked to the source generator change: #3846. Apologies. This was made 'opt-in' to reduce the possibility of breaking compilation of existing WPF applications, but will eventually be turned on by default in .NET 6.0. |
I tried the property that @Zalutskii was mentioning above One think I would like to point out, that while most people (and that attribute) are talking about Update: I did it wrong. Attribute works perfectly. |
here I give an example of how to add the Source Generator as a Project Reference. <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
...
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
...
</PropertyGroup>
<ItemGroup>
...
<PackageReference Include="RxSourceGenerator" Version="1.1.2" />
...
</ItemGroup> Microsoft Visual Studio Community 2019 16.8.4 |
I'm trying to port VB "My WPF extension" of .NET Framework to .NET 5. Here's my project: https://github.com/Nukepayload2/MyWpfExtensionGenerator |
Yes this definitely works like @Zalutskii describes. The new attribute fixes the issue. Turning this on by default is tracked by #3974. So to me (the author of this issue) this is fixed. Feel free to reopen if issues occur. |
It's also tracked here for the .NET SDK for 5.0.200: dotnet/sdk#15395 |
I'm using VisualStudio 16.8.5, not preview. In my case the @Zalutskii solution works for simple class generation only, but not for more complicated generator. When I'm trying to apply [AutoNotify] attribute from samples to my ViewModel, then all errors come back again. UPD. I found a solution here. In addition to
|
Version Used:
dotnet 5 preview 8, visual studio 16.8 preview 2
Steps to Reproduce:
Create fresh WPF project from VS modify project like this:
Expected Behavior:
The source generator referenced works for me in a console dotnet core app. I would expect this to work in a WPF project too.
Actual Behavior:
In a freshly created WPF (dotnet core) project from the VS-template, however the generator does not seem to run.
Is this intended behavior?
As the generator is not used at all, I have not included it here. It is a slight variation of the HelloWorld sample.
The text was updated successfully, but these errors were encountered: