【问题标题】:.NET 6 source generators and C# 9 syntax.NET 6 源代码生成器和 C# 9 语法
【发布时间】:2022-06-11 04:06:20
【问题描述】:

如果源代码生成器项目必须以netstandard2.0 (C# 7.3) 为目标,那么.NET 6 incremental generator documentation 中的示例如何以及为什么像静态匿名函数一样使用C# 9 语法?

来自文档,按宽度格式化:

IncrementalValuesProvider<AdditionalText> textFiles =
   context.AdditionalTextsProvider.Where(static file =>
      file.Path.EndsWith(".txt"));

【问题讨论】:

  • 如果您以netstandard2.0 为目标,您可以实际上使用比7.3 更高的C# 语言版本,这是构建系统中的人为限制(grrrrr)。它很复杂,到目前为止我只让它在多目标项目中工作,例如meziantou.net/…(哦,由于某种原因,我所有的多目标项目都确实减慢了 VS 2019 的速度......)
  • @Dai This blog post 也掩盖了它。也许我是唯一一个没有破解我的语言版本的人!

标签: c# .net-6.0 csharp-source-generator


【解决方案1】:

只需将.csproj文件中的C#版本改为9,如&lt;LangVersion&gt;9.0&lt;/LangVersion&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 2021-12-27
    • 2021-09-17
    • 1970-01-01
    • 2023-01-03
    • 1970-01-01
    • 2011-01-02
    相关资源
    最近更新 更多