首页 问答 .NET Source Generators 的 target framework 问题
问题详情

实现 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>

版权:言论仅代表个人观点,不代表官方立场。转载请注明出处:https://www.stntk.com/question/2712.html

发表评论
暂无评论

还没有评论呢,快来抢沙发~

点击联系客服

在线时间:8:00-16:00

客服QQ

70068002

客服电话

400-888-8888

客服邮箱

70068002@qq.com

扫描二维码

关注微信公众号

扫描二维码

手机访问本站