CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.2k stars 378 forks source link

[Bug] Extention method TextColorTo() generates warnings #411

Closed RichardMarsh closed 2 years ago

RichardMarsh commented 2 years ago

Description

The TextColorTo extention methods are being created via SourceGenerators. These source generators however create CS0436 warnings when the CommunityToolkit is used in a library.

C:\Users\R\source\repos\CommunityToolkitSample\CommunityToolkitSample.App\CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\LabelTextColorTo_71aacac4-5ef7-473e-aae1-1fe5429261f1.g.shared.cs(41,89,41,119): warning CS0436: The type 'ColorAnimationExtensions_Label' in 'CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\LabelTextColorTo_71aacac4-5ef7-473e-aae1-1fe5429261f1.g.shared.cs' conflicts with the imported type 'ColorAnimationExtensions_Label' in 'CommunityToolkitSample.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\LabelTextColorTo_71aacac4-5ef7-473e-aae1-1fe5429261f1.g.shared.cs'.

Link to Reproduction Sample

https://github.com/RichardMarsh/CommunityToolkitSample

Steps to Reproduce

  1. Create a .NET MAUI Library that references the CommunityToolkit
  2. Create a .NET MAUI app that references the library created in step 1
  3. Build

Basic Information

Workaround

Remove the analyzer from the custom library project. However that means the custom library does not have access to those features.

`

`

pictos commented 2 years ago

@RichardMarsh I tried your sample attached and everything runs like a charm as you can see in the screenshot below image

Also, I noticed some wrong configs on your csproj.

RichardMarsh commented 2 years ago

@pictos Thanks for taking the time to look into this.

Not sure why you aren't getting warnings, but here's a screenshot

image

Also, you said there's some config issues? I just created the default projects and added CommunityToolkit. What was wrong with the configs?

VladislavAntonyuk commented 2 years ago

I was able to reproduce it: image this happens because SourceGenerator files were generated for both the app and library. To fix the issue replace the PackageReference with:

<PackageReference Include="CommunityToolkit.Maui" Version="1.0.0-rc3">
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
RichardMarsh commented 2 years ago
<PackageReference Include="CommunityToolkit.Maui" Version="1.0.0-rc3">
  <PrivateAssets>all</PrivateAssets>
</PackageReference>

Thanks for this suggestion. However the build warnings will reappear if I then add the CommunityToolkit.Maui package to my App ,if for some reason my app needs to use the CommunityToolkit directly.

Unless I'm doing it incorrectly, which is also possible.

marcmognol commented 2 years ago

Hello,

I have exactly the same warning message when I add a xUnit project to my solution and my MAUI project as a reference of my xUnit project.

VladislavAntonyuk commented 2 years ago

@pictos is it fixed with 1.1.0 release?

marcmognol commented 2 years ago

@pictos is it fixed with 1.1.0 release?

No. Warnings still there.

pictos commented 2 years ago

We didn't change anything on that... And not sure if we can... SG will generate code for all assemblies that reference the MCT. TBH not sure if we can do something on that, maybe the lib that uses MCT needs to do some work, maybe exposing the MCT to the consumers, that way the App doesn't need to install the MCT by itself? Or suppressing the generated files that way it doesn't leak to consumers?

If anyone knows something about SG that can prevent that, let us know then we can see if makes sense to implement it here.