wpf: Source Generator support for WPF project blocked?
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:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SourceGenerators\SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 12
- Comments: 20 (8 by maintainers)
Intent is to fix the behavior, not document it.
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 found a hint on how to solve the problem here https://github.com/dotnet/wpf/issues/3974
In my case it works.
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.
here I give an example of how to add the Source Generator as a Project Reference. If you want to add as NuGet it will look like this:
</Project>Microsoft Visual Studio Community 2019 16.8.4 If you use resharper, it must be the latest version, or disabled.
@Marv51 from another issue