Sergio0694 / PolySharp

PolySharp provides generated, source-only polyfills for C# language features, to easily use all runtime-agnostic features downlevel. Add a reference, set your C# version to latest and have fun! 🚀
MIT License
1.77k stars 46 forks source link

PolySharp.SourceGenerators.PolyfillGenerator is not generating files #74

Open martinsuchan opened 1 year ago

martinsuchan commented 1 year ago

In our solution of about 200 projects, all targeting .NET 4.7.2 and using SDK Style format, one project does not have any polyfills generated, see the screenshot. I have no idea why it's not working for this one specific project. PXL_20230609_132001143

It should generate polyfills in all projects. Is there a way how can I debug this package or polyfill? Is there any logging that I can read or exception that is thrown?

System info

Polysharp 1.13.2, VS 2022 17.6.2, project targeting .NET 4.7.2 in SDK style. (Have you tested Polysharp in .NET 4.7.2 SDK style projects?)

Additional context (optional)

Note in each of our projects I can see this error/warning in the Analyzers section: POLYSP0003 Unsupported C# version, even though it works in all but one project. Possibly false positive?

martinsuchan commented 1 year ago

Forgot to mention we have defined LangVersion 11.0 in our Directory.Build.props file.

martinsuchan commented 1 year ago

I have repro! Repro.zip

Tl;dr if a dependency project has PolySharp installed and uses InternalsVisibleTo("App"), then polyfills are not generated in App even when PolySharp is also included, but in this case C#11 features work becuase internals from dependency project are used. The problem is if there are two dependencies with PolySharp and both with InternalsVisibleTo("App"). In this case it's not possible to use records/init properties and other features in App because there are two attributes available in the same namespace - ambiguation for the compiler.

How to solve it? Ideally generate polyfills even if there are polyfills available through InternalsVisibleTo from other asembly. Also if possible fix the issue with POLYSP0003 warning.

martinsuchan commented 1 year ago

Looks like a duplicate of https://github.com/Sergio0694/PolySharp/issues/50