CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 301 forks source link

Microsoft.CSharp.Core.targets errors and source generator errors #573

Closed RabbitAth closed 1 year ago

RabbitAth commented 1 year ago

I for the first time installed CommunityToolKit.Mvvm Nuget version 8.1.0 to and existing project with some existing ViewModels. I have ended up with over 250 errors in Microsoft.CSharp.Core.targets. I had attempted to create a new BaseViewModel to inherit from and a new ViewModel and build my project when the errors appeared.

Using Visual Studio version 17.3.4 Target framework for the project is net6.0 (this is a .Net MAUI Class Library I believe) Visual Studio Project Properties -> Build -> Advanced has a language version of 10.0

I have also ended up with errors and warnings in the SourceGenerators such as: MVVMTK0008: Unsupported C# language version (Per above I don't think this should be an issue) MVVMTK0020: Invalid use of attributes dependent on [ObservableProperty] MVVMTK0033: Inherit from Observable Object instead of using [INotifyPropertyChanged] MVVMTK0033: Inherit from ObservableObject instead of using [ObservableObject] MVVMTK0034: Direct field reference to [ObservableProperty] backing field

Do I have a version mismatch issue? Any help would be appreciated, thank you.

Sergio0694 commented 1 year ago

There isn't enough info here to know what could be going on. Are you able to provide a minimal repro? Have you also tried updating VS to the latest stable release (that'd be VS 17.4.4 I believe) to see if it helps?

RabbitAth commented 1 year ago

Previously avoided updating VS as I believe I had issues with 17.4.0 or 17.4.3 and parts of MAUI so I rolled back.

Just now updated to VS 17.4.4 on a different machine. Still seeing source generator errors and warnings MVVMTK0000 under CommunityTookit.Mvvm.SourceGenerators in net6.0, net6.0-windows, etc. However I am able to build and run my MAUI app which references the library with the MVVM toolkit, so far no issue's with errors related to Microsoft.CSharp.Core.targets. Not sure if the MVVMTK0000's are an issue.

Is providing a repo still useful? I was working on it but on the VS 17.3.4 machine. Will likely update the version.

Sergio0694 commented 1 year ago

Yes, if you could provide a minimal repro that would help 🙂 If you can make one in a plain .NET project with no MAUI or other dependencies, that's much better still.

RabbitAth commented 1 year ago

image

VS 17.3.4 - Errors from minimal git project (these errors do not exist in VS 17.4.4)

RabbitAth commented 1 year ago

image

Source generator errors that exist in both VS 17.3.4 and 17.4.4

RabbitAth commented 1 year ago

Minimal Project Repository

Sergio0694 commented 1 year ago

Those errors in 17.3.4 are expected, it's a bug in Roslyn that was fixed in 17.3.6. See #493. I'll try out the repro for the other ones, thank you! 🙂

Sergio0694 commented 1 year ago

The repro builds just fine for me on VS 17.4.4 🤷 Just with a couple warnings for those nullable properties.

Sergio0694 commented 1 year ago

Closing for now, but feel free to update if you have more info or find another scenario that can repro 🙂

RabbitAth commented 1 year ago

Okay thank you! Please note that is a new project, that was created in 17.3.4 and then opened again and tested in 17.4.4. Which could be the cause. I do not see the same issue's in the sample MonkeyFinder project from James Montemagno using toolkit version 8.0.0 which was downloaded and run on VS 17.3.4.