Skip to content

[Bug] SB.SourceGenerator 使用 Microsoft.CodeAnalysis.Common Version="*",在 .NET SDK 9 下触发 CS9057 导致 tools 构建失败 #402

Description

@qiyuewuyi2333

环境

  • OS: Windows 10/11
  • .NET SDK: 9.0.310
  • 分支: engine
  • 命令: dotnet run SB build --mode=release --category=tools

现象

构建 SB.Core 时出现:

C:\Users\qiyuewuyi\Dev\SakuraEngine engine: dotnet run SB build --mode=release --category=tools
CSC : warning CS9057: Analyzer assembly 'C:\Users\qiyuewuyi\Dev\SakuraEngine\engine\tools\.tools\SB.SourceGenerator\bin\Debug\netstandard2.0\SB.SourceGenerator.dll' cannot be used because it references version '5.6.0.0'
of the compiler, which is newer than the currently running version '4.14.0.0'.
C:\Users\qiyuewuyi\Dev\SakuraEngine\engine\tools\SB\SB.Core\BuildSystem\BuildSystem.Configure.cs(13,24): error CS1061: 'Target' does not contain a definition for 'DebugSymbols' and no accessible extension method 'DebugSymbols' accepting a first argument of type 'Target' could be found (are you missing a using directive or an assembly reference?)
C:\Users\qiyuewuyi\Dev\SakuraEngine\engine\tools\SB\SB.Core\BuildSystem\BuildSystem.Configure.cs(20,24): error CS1061: 'Target' does not contain a definition for 'DebugSymbols' and no accessible extension method 'DebugSymbols' accepting a first argument of type 'Target' could be found (are you missing a using directive or an assembly reference?)
C:\Users\qiyuewuyi\Dev\SakuraEngine\engine\tools\SB\SB.Core\BuildSystem\BuildSystem.Configure.cs(27,24): error CS1061: 'Target' does not contain a definition for 'DebugSymbols' and no accessible extension method 'DebugSymbols' accepting a first argument of type 'Target' could be found (are you missing a using directive or an assembly reference?)
C:\Users\qiyuewuyi\Dev\SakuraEngine\engine\tools\SB\SB.Core\BuildSystem\BuildSystem.Configure.cs(39,28): error CS1061: 'Target' does not contain a definition for 'Link' and no accessible extension method 'Link' accepting a first argument of type 'Target' could be found (are you missing a using directive or an assembly reference?)
C:\Users\qiyuewuyi\Dev\SakuraEngine\engine\tools\SB\SB.Core\BuildSystem\BuildSystem.Configure.cs(50,28): error CS1061: 'Target' does not contain a definition for 'CppFlags' and no accessible extension method 'CppFlags' accepting a first argument of type 'Target' could be found (are you missing a using directive or an assembly reference?)

可能的原因

SkrSharp.Codegen项目配置中声明引用了

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
  </ItemGroup>


SB.SourceGenerator引用了

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="*" />
  </ItemGroup>

猜测是两者版本不一致导致的,Version=* 会导致请求引用最新版本的dll也就是5.6,和上面的4.14版本不一致

尝试的修复

再将上面两者统一改成4.14之后,构建通过

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions