实现 IIncrementalGenerator 的类中,[Generator(LanguageNames.CSharp)] 出现编译警告
[Generator(LanguageNames.CSharp)]
public class PatternsGenerator : IIncrementalGenerator
{
//....
}
警告信息如下
This compiler extension should not be implemented in an assembly with target framework '.NET 10.0'. References to other target frameworks will cause the compiler to behave unpredictably.
csproj 中 PropertyGroup 部分的内容
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
target framework 需要改为 netstandard2.0
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>