canton7 / PropertyChanged.SourceGenerator

Powerful INotifyPropertyChanged / INotifyPropertyChanging Source Generator, which generates INPC boilerplate for you as part of your build. Supports features such as automatic and manual dependencies between properties, notifications when specific properties change, and more.
MIT License
138 stars 14 forks source link

New WPF App: Duplicate Generator-Code generated #22

Closed warappa closed 2 years ago

warappa commented 2 years ago

Description If I create a fresh .NET 6 WPF application, install this package, add the required IncludePackageReferencesDuringMarkupCompilation and run it, many build errors orrur.

Cleaning, rebuilding, or even restarting Visual Studio did not change outcome.

To Reproduce

Error Messages

...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(38,20,38,35): error CS0101: The namespace 'PropertyChanged.SourceGenerator' already contains a definition for 'NotifyAttribute'
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(72,20,72,39): error CS0101: The namespace 'PropertyChanged.SourceGenerator' already contains a definition for 'AlsoNotifyAttribute'
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(86,20,86,38): error CS0101: The namespace 'PropertyChanged.SourceGenerator' already contains a definition for 'DependsOnAttribute'
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(100,20,100,38): error CS0101: The namespace 'PropertyChanged.SourceGenerator' already contains a definition for 'IsChangedAttribute'
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(10,19,10,25): error CS0101: The namespace 'PropertyChanged.SourceGenerator' already contains a definition for 'Getter'
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(23,19,23,25): error CS0101: The namespace 'PropertyChanged.SourceGenerator' already contains a definition for 'Setter'
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(36,6,36,35): error CS0579: Duplicate 'global::System.AttributeUsage' attribute
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(84,6,84,35): error CS0579: Duplicate 'global::System.AttributeUsage' attribute
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(98,6,98,35): error CS0579: Duplicate 'global::System.AttributeUsage' attribute
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(70,6,70,35): error CS0579: Duplicate 'global::System.AttributeUsage' attribute
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(43,16,43,31): error CS0111: Type 'NotifyAttribute' already defines a member called 'NotifyAttribute' with the same parameter types
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(51,16,51,31): error CS0111: Type 'NotifyAttribute' already defines a member called 'NotifyAttribute' with the same parameter types
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(58,16,58,31): error CS0111: Type 'NotifyAttribute' already defines a member called 'NotifyAttribute' with the same parameter types
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(64,16,64,31): error CS0111: Type 'NotifyAttribute' already defines a member called 'NotifyAttribute' with the same parameter types
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(92,16,92,34): error CS0111: Type 'DependsOnAttribute' already defines a member called 'DependsOnAttribute' with the same parameter types
...\WpfApp1\PropertyChanged.SourceGenerator\PropertyChanged.SourceGenerator.PropertyChangedSourceGenerator\Attributes.cs(78,16,78,35): error CS0111: Type 'AlsoNotifyAttribute' already defines a member called 'AlsoNotifyAttribute' with the same parameter types

Version Info

Additional Info Visual Studio 2022 (17.4.0 Preview 1) Tried with .NET 7.0.0-preview.3.22175.4 and 6.0.400 (via global.json).

dotnet --info

.NET SDK (reflecting any global.json):
 Version:   6.0.400
 Commit:    7771abd614

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.400\

Host (useful for support):
  Version: 7.0.0-preview.3.22175.4
  Commit:  162f83657c

.NET SDKs installed:
  3.1.422 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  5.0.411 [C:\Program Files\dotnet\sdk]
  6.0.200-preview.22055.15 [C:\Program Files\dotnet\sdk]
  6.0.303 [C:\Program Files\dotnet\sdk]
  6.0.400 [C:\Program Files\dotnet\sdk]
  7.0.100-preview.3.22179.4 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-preview.3.22178.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Core.App]
  Microsoft.NETCore.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-preview.3.22175.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-preview.3.22177.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
canton7 commented 2 years ago

Sounds like this WPF bug. Does this workaround work? See also https://github.com/canton7/PropertyChanged.SourceGenerator/discussions/19.

warappa commented 2 years ago

Wow, that was fast - and you are totally right, it's a WPF bug!

It works with the fix referenced!

canton7 commented 2 years ago

Good to hear! I've added a note to the README, although it's probably fixed in a released VS version by now.