Closed latonz closed 1 year ago
Can you provide a repro project (zip or github repo)? On my side it seems to be supported. You can see that ClassLib2 doesn't contain any generated files.
Thank you for the fast response. I poked around and found out that ClassLibrary2
used a later tfm net7.0
, but ClassLibrary1
had a tfm of netstandard2.0
. I added net7.0
as tfm to ClassLibrary1
and it worked.
The problem was that ClassLibrary1
had only netstandard2.0
as tfm and therefore generated the polyfills while also having InternalsVisibleTo
set for ClassLibrary2
, but ClassLibrary2
had those types already due to the later tfm. I'm not even sure if this can be fixed without adding multitargeting to ClassLibrary1
🤔 Repro: https://github.com/latonz/duplicated-polyfill-repro
Btw: thank you for this great source generator and your interesting blog posts!
Thanks for the repro. What you can do is to not generate the conflicting types if you don't use them:
<PropertyGroup>
<MeziantouPolyfill_IncludedPolyfills>T:Type1;T:Type2;M:Member1</MeziantouPolyfill_IncludedPolyfills>
<MeziantouPolyfill_ExcludedPolyfills>M:System.</MeziantouPolyfill_ExcludedPolyfills>
</PropertyGroup>
T:
matches all types, T:System.Diagnostics.
matches all types starting with System.Diagnostics.
.Debug.g.cs
file<EmitCompilerGeneratedFiles>True</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
However, if you need to use conflicting types, I don't think there is a way to do it properly.
Thank you for your explanations. I'll try using multi-targeting which should work in my setup.
If an assembly has
InternalsVisibleTo
set to another assembly, andMeziantou.Polyfill
is added to both projects, polyfills are generated for both. This leads to duplicated types.Eg (Assembly 1 has
InternalsVisibleTo("Assembly 2")
):Reproduction steps:
Meziantou.Polyfill
to aDirectory.Build.props
in the solutions directoryDirectory.Build.props
netstandard2.0
) in theDirectory.Build.props
[assembly: InternalsVisibleTo("Project2")]
to the first project