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
2.99k stars 294 forks source link

.netframework project #715

Closed AmeerMansour closed 1 year ago

AmeerMansour commented 1 year ago

Describe the bug

i am trying to use it for a .netframework project but it seems it doesn't add anaylzers.

image

Steps to reproduce

1.Create wpf project ( .Net framework) 2.Add community toolkit

Expected behavior

Analyzers should be automatically added.

IDE and version

VS 2022

Nuget packages

Nuget package version(s)

8.0.2

Help us help you

Yes, but only if others can assist

Sergio0694 commented 1 year ago

Hey there! We added a new analyzer for this scenario, could you try using our latest preview and checking with that?

Add our preview feed:

https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-MainLatest/nuget/v3/index.json

And then install the lates MVVM Toolkit 8.2.1 preview build you see there. Thank you! 🙂

AmeerMansour commented 1 year ago

Still not working ... I believe there is another issue. to use it in .net frameworks projects: I had to add "**<LangVersion>latest</LangVersion>**" or "**<LangVersion>9.0</LangVersion>**" to my project then manually add the analyzer

AmeerMansour commented 1 year ago

Also code fixer analyzer is not being added to any .net framework project .

Sergio0694 commented 1 year ago

So, the analyzers not working are by design, as you're using packages.config, which is not supported. But, with 8.2.1 you should be seeing a warning about this. Are you not seeing it? You should see this warning:

https://github.com/CommunityToolkit/dotnet/blob/d6eb5ccd83bbf162f1cd6bf170f8f540e9f60d47/src/CommunityToolkit.Mvvm/CommunityToolkit.Mvvm.targets#L143-L146

AmeerMansour commented 1 year ago

image

i got no warrning.

Sergio0694 commented 1 year ago

You do have the warning, you can see it in the first line:

Thus is by design: packages.config is not supported. You need to switch to <PackageReference> to use the generators 🙂

AmeerMansour commented 1 year ago

that will be a very big and complicated issue to convert my existing project to use PackageReference some other nuget will fail and will crash my project.

Sergio0694 commented 1 year ago

I'm afraid your alternative is just to not use the generators for now then 🥲 To clarify: this is not a limitation with the MVVM Toolkit. The C# compiler (Roslyn) just doesn't support source generators at all for projects using packages.config, so there's nothing we can do from our end to make our generators work there unfortunately.