admin管理员组

文章数量:1124655

I have a source generator which completes an implementation of a library, this means there is a source generator assembly and a library assembly. In order for the source generator to create the correct implementation it needs to know the name of a few types in the library, these just have to be the name (but generic type information would be a bonus).

The problem is the library runtime is 8.0 and the source generator has to be net standard 2.0 which means I can't have a normal dependency to the library from the source generator.

Is there a way to include type details from a non-net standard 2.0 compliant codebase in a source generator?


What I've tried:

  • Including loose C# files as needed: Core interfaces make use of non- standard 2.0 features so don't compile
    • #define NETSTANDARD2_0 to exclude features, while this would work it requires a large amount of defines to block out features and methods. It's possible some of them need to be known about by the source generator
  • Shared projects: Don't allow for types that use higher level features like static abstract interface methods, works for simpler libraries
  • Reference Assemblies: Don't produce runtime agnostic output assemblies, the library must compile with standard 2.0 even if only using it using nameof() to fill in type names

Current Solution

I have a single file with a lot of const string instances which have the names of types and namespaces. If the types move or are renamed the source generator either can't find the members to link against or produces invalid code which points at old types (or old type locations)

本文标签: cGet type names for nameof() from another assembly without runtime restrictionsStack Overflow