[BUG] CS0436 compiler warning because of source generators when using InternalsVisibleTo
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- I have read the “Reporting a bug” section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
The source generators of the CommunityToolkit.Maui generate compiler warnings in our solution.
We use the [assembly: InternalsVisibleTo(..]
attribute so that we can access internal members within unit tests. But the source generators create the same internal classes in all projects. So the compiler warns about:
Warning CS0436: The type 'ColorAnimationExtensions_TimePicker' in 'CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\TimePickerTextColorTo.g.shared.cs' conflicts with the imported type...
Complete warning text:
[warning]D:\7\s\...\Foo.Test\CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\TimePickerTextColorTo.g.shared.cs(63,89): Warning CS0436: The type 'ColorAnimationExtensions_TimePicker' in 'CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\TimePickerTextColorTo.g.shared.cs' conflicts with the imported type 'ColorAnimationExtensions_TimePicker' in 'FooLib, Version=3.0.400.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'CommunityToolkit.Maui.SourceGenerators\CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator\TimePickerTextColorTo.g.shared.cs'.
Expected Behavior
no compiler warnings
Workaround
I have added <NoWarn>1701;1702;CS0436</NoWarn>
to the unit test project file. This suppress the compiler warning.
Steps To Reproduce
- Just add a C# project (e.g. unit test project) that references a project which includes the CommunityToolkti.Maui.
- Add
InternalsVisibleTo
attribute so that the newly added project can access the internal members of the referenced project. - Build and see the compiler warnings
Link to public reproduction project repository
Environment
- .NET MAUI CommunityToolkit:5.0.0
Anything else?
No response
Issue Analytics
- State:
- Created 4 months ago
- Comments:11 (4 by maintainers)
You should not include analyzers/source generators etc in test project:
Exclude them to remove warnings:
@omghb, What I posted isn’t a workaround, it’s how you can exclude SG from the build. Your sample project doesn’t reflect the reality of your project, since you just added a Maui app and Unit test, there are no external libs there… We can just provide options for what we see