Version Used:
VS 16.7 P2
Steps to Reproduce:
Compile SG with target framework netstandard2.1 or above
Expected Behavior:
SG will be used and generate code
Actual Behavior:
SG is not used
The restriction of SG to netstandard2.0 has an effect on the available language functions. For example, interfaces with default implementations cannot be used. While the generated code is not affected, the SG code itself should not be limited to an outdated standard.
because the compiler must run on both .NET Framework and .NET Core all generators must target .NET Standard 2.0
I'm probably missing a big part here, but why exactly does the source generator have to run on both .NET Framework and .NET Core and not the actual target framework?
@RayKoopa the "actual target framework" is not applicable to this situation. Your source generator is a plugin that is loaded by the C# compiler. It therefore needs to be able to be loaded and run in all the environments that the C# compiler does.
Lets say at some point in the future the C# compiler runs on only .NET Core. Even in this case you cannot target a newer target framework than what the compiler supports. Meaning that if the compiler is compiled against .NET 5 you cannot target .NET 6 in your source generator.
You're right, I had an error in my thinking. I probably spent too much time realizing why my source generator was "not found" because of its project targeting netstandard2.1 :D
(Maybe it should report an exact message that a source generator project must target netstandard2.0 currently, instead of claiming it could not find it's assembly file, but that's another topic.)
@RayKoopa I agree we should offer a better message here. I hope to update the tooling soon to also warn about this case