Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleInitializerAttribute source generated, causing conflict #1464

Closed
AArnott opened this issue Dec 26, 2024 · 2 comments · Fixed by #1476
Closed

ModuleInitializerAttribute source generated, causing conflict #1464

AArnott opened this issue Dec 26, 2024 · 2 comments · Fixed by #1476

Comments

@AArnott
Copy link
Contributor

AArnott commented Dec 26, 2024

You predicted it, and it happened. I'm using "PolySharp" in my test project already and it's generating the ModuleInitializerAttribute for me, but then your TUnit.Core.SourceGenerator comes along and emits it as well, causing a CS0101 error:

The namespace 'System.Runtime.CompilerServices' already contains a definition for 'ModuleInitializerAttribute'

Is there a way to turn yours off? (I thought you'd decided to not emit this, and rather to document that users may need to reference or declare a polyfill themselves).

@AArnott
Copy link
Contributor Author

AArnott commented Dec 26, 2024

I was able to workaround this by defining my own (3rd, ironically) polyfill as an ordinary source file:

namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Method, Inherited = false)]
internal sealed class ModuleInitializerAttribute : Attribute;

This gets both source generators to stop emitting it, avoiding the collision.

Still, it adds friction (and the workaround isn't particularly discoverable if you're not fluent in how source generators may work) to migrating to TUnit.

@thomhurst
Copy link
Owner

Maybe adding a project property would be useful to disable it?

<EnableTUnitPolyfills>false</EnableTUnitPolyfills>

@thomhurst thomhurst linked a pull request Dec 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants