3

I have a project that uses code generators to automatically provide INotifyPropertyChanged support for fields. Some classes in the project implement an interface that has some properties that ought to be generated by that source generator for the implementing class. Now, Visual Studio does not show me error messages while editing any of these classes, but building the project yields errors for the unimplemented properties of the interface. I can navigate to the generated properties and intellisense finds them as well, so the properties should be present.

Here's a short example:

IMyInterface.cs:

public interface IMyInterface
{
    string Title { get; set; }
}

AClass.cs:

public partial class AClass : BaseClassForINPC, IMyInterface
{
    [NotificationProperty]
    private string title;
}

And the generated file AClass.g.np.cs

partial class AClass
{
    public string Title
    {
        get => title;
        set => SetValue(ref title, value, "Title");
    }
}

The project targets .NET Core 3.1 + WPF. Using the source generator in a project that targets .NET Standard 2.0 works fine. Am i missing something or is this just not yet supported for such projects?

Edit
I've tested some configurations and got the following results:

  • .NET Standard 2.0 works as expected
  • .NET Standard 2.1 as well
  • a project based on the WPF Custom Control Library (.NET) template works
    • Configuring the project to look the same as the WPF App (.NET) template (= .csproj files look the same) works
    • works when targeting either .NET Core 3.1 and .NET 5
  • a fresh WPF App (.NET) template based project yields the mentioned errors (for 3.1 and 5)

However, removing all .xaml files in the project from the build (e.g. App.xaml or MainWindow.xaml plus their code behing file) resolves the issue. If you add those files to the library project, it will fail to build as well with the same errors). So my first thought is: you can't yet use source generators with .xaml files in the same project. The initial question remains though. Did i miss something in the setup or is it just not yet supported?

Streamline
  • 952
  • 1
  • 15
  • 23

0 Answers0