Azure DevOps:迁移到 .NET Core 3.0 后管道中断

Azure DevOps: Pipeline broken after migrating to .NET Core 3.0

我有一个包含多个 .NET Standard 2.0、.NET Standard 2.1、.NET Core 3.0 和完整的 .NET Framework 4.8 项目的解决方案。管道如下所示:

  pool:
    name: Azure Pipelines
    demands:
    - msbuild
    - visualstudio

  variables:
    BuildPlatform: 'any cpu'
    BuildConfiguration: 'release'

  steps:
  - task: UseDotNet@2
    displayName: 'Use .NET Core sdk 3.0'
    inputs:
      version: 3.0.100

  - task: DotNetCoreCLI@2
    displayName: 'dotnet restore'
    inputs:
      command: restore
      projects: '**/*.csproj'

  - task: NuGetToolInstaller@1
    displayName: 'Use NuGet 4.9.1'
    inputs:
      versionSpec: 4.9.1
      checkLatest: true

  - task: NuGetCommand@2
    displayName: 'NuGet restore'

  - task: VSBuild@1
    displayName: 'Build solution **\*.sln'
    inputs:
      vsVersion: 16.0
      platform: '$(BuildPlatform)'
      configuration: '$(BuildConfiguration)'
      clean: true

  - task: DotNetCoreCLI@2
    displayName: 'dotnet test'
    inputs:
      command: test
      projects: '**/*tests.csproj'

  - task: PublishSymbols@2
    displayName: 'Publish symbols path'
    inputs:
      PublishSymbols: false

安装正确的 SDK 版本后,管道运行 dotnet restore 以下载 .NET Standard 和 .NET Core 项目使用的所有 NuGet 包。之后,它安装 NuGet 并使用它来恢复完整的 .NET Framework 项目使用的 NuGet 包。

但是,迁移到 .NET Core 3.0 后,NuGet 还原失败并出现以下错误:

[error] The nuget command failed with exit code(1) and error(NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1)

NU1202: Package Microsoft.EntityFrameworkCore.Tools 3.0.0 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.Tools 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1) NU1202: Package Microsoft.EntityFrameworkCore.Relational 3.0.0 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.Relational 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1) Errors in d:\a\s\Pagesp.ChaveMovel.AspNetCore.Site.Identity.v2\Pagesp.ChaveMovel.AspNetCore.Site.Identity.v2.csproj NU1202: Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.SqlServer 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1) NU1202: Package Microsoft.EntityFrameworkCore.Tools 3.0.0 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.Tools 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1) NU1202: Package Microsoft.EntityFrameworkCore.Relational 3.0.0 is not compatible with netcoreapp3.0 (.NETCoreApp,Version=v3.0). Package Microsoft.EntityFrameworkCore.Relational 3.0.0 supports: netstandard2.1 (.NETStandard,Version=v2.1))

[error] Packages failed to restore

关于如何解决这个问题有什么想法吗?

1) 我成功地使用以下方法重现了您的问题:

  • 你的管道
  • 示例项目(source

2) 我在Nuget任务中注释掉了versionSpec,之后管道成功完成:

- task: NuGetToolInstaller@1
  displayName: 'Use NuGet 4.9.1'
  inputs:
    # versionSpec: 4.9.1
    checkLatest: true

3) 自动安装的NuGet版本为5.3.0