【问题标题】:Azure DevOps build fails after upgrading app to from ASP.NET Core 2.2 to ASP.NET Core 3.1将应用程序从 ASP.NET Core 2.2 升级到 ASP.NET Core 3.1 后,Azure DevOps 构建失败
【发布时间】:2020-05-25 04:20:12
【问题描述】:

我有一个在本地运行良好的构建(VSCode、.NET Core 3.1.101),但在 Azure DevOps Pipeline 中运行时失败并显示以下消息。

我的管道被精简到最基本的:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

这会导致以下错误消息:

.NET Core SDK 版本 3.1.101 至少需要 16.3.0 版本的 MSBuild。当前可用的 MSBuild 版本是 15.9.21.664。将 global.json 中指定的 .NET Core SDK 更改为需要当前可用的 MSBuild 版本的旧版本。

我找不到更改管道运行的 MSBuild 版本的方法,更改为旧版本的 .NET Core 肯定会破坏升级的目的?

有没有办法在 Azure DevOps 上构建 .NET Core 3.1 解决方案?

【问题讨论】:

  • 你能把你的任务是什么样子的吗
  • 好点。我已经为要质疑的构建步骤添加了 YAML。
  • 16.4 的 windows-2019 映像,但您指的是 15.9。版本,所以它似乎与你的项目有关,你能分享一个样本给我们来重现这个问题吗?

标签: azure azure-devops msbuild asp.net-core-3.1


【解决方案1】:

我没有看到您在任何地方都有 dotnet build 任务,您需要配置版本的 dotnetbuild 任务,

steps:

    - task: UseDotNet@2 
      displayName: ".NET Core 3.1.x"
      inputs:
        version: '3.1.x'
        packageType: sdk
    - script: dotnet build --configuration $(buildConfiguration)
      displayName: 'dotnet build $(buildConfiguration)'

请参阅此article

【讨论】:

  • 不,它仍然无法正常工作Version 3.0.102 of the .NET Core SDK requires at least version 16.3.0 of MSBuild. The current available version of MSBuild is 15.9.21.664. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
  • 我不认为它与天蓝色的 devops 相关,我怀疑这里有类似的东西stackoverflow.com/questions/55420731/…
  • 我想我明白了! stackoverflow.com/a/58168141/1958882 好吧,它带有一些警告,但它似乎正在工作。
  • 我试过了 - 删除了 NuGet 命令并替换为 dotnet restore。该位有效,但现在 dotnet 构建给出了错误:无法识别 TargetFramework 值“netcoreapp3.1”。它可能拼写错误。如果不是,则必须明确指定 TargetFrameworkIdentifier 和/或 TargetFrameworkVersion 属性
  • 我剥离了管道定义,只包括它失败的位置。原版有 dotnet 构建位,但并没有那么远。
【解决方案2】:

您应该能够恢复 nuget 包,使用此 YAML 编译和运行单元测试


pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Release'
  rootDirectory: '$(Build.SourcesDirectory)'

steps:

- task: DotNetCoreCLI@2
  displayName: Restore nuget packages
  inputs:
    command: restore
    projects: '**/*.csproj'
    workingDirectory: $(rootDirectory)

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: build
    projects: '$(rootDirectory)/*.sln'
    arguments: '--configuration $(buildConfiguration)'

# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true'
    workingDirectory: $(rootDirectory)

我假设您的解决方案文件位于根目录中。如果您使用全局 json,请将 sdk 版本设置为 3.1.201 否则可能需要另一个 steo。

global.json

{
  "sdk": {
    "version": "3.1.201",
    "rollForward": "latestFeature"
  }
}

【讨论】:

    猜你喜欢
    • 2020-01-29
    • 2019-08-14
    • 1970-01-01
    • 2021-02-26
    • 2019-05-08
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 2019-07-12
    相关资源
    最近更新 更多