Blazor .NET 5 的 Azure CI 管道不起作用

Azure CI pipeline for Blazor .NET 5 doesn't work

我有一个用于 WebAssembly Blazor 应用程序的现有 Azure CI 管道,它适用于 .NET Core 3.1。

我将应用程序升级为使用 .NET 5 RC,但管道不再工作。

根据建议,我删除了 NuGet 任务,并插入了两个新任务:

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100-rc.1.20452.10'
  inputs:
    version: '5.0.100-rc.1.20452.10'
    includePreviewVersions: true

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

有效。

但是构建任务失败了:

...
ValidateSolutionConfiguration:
  Building solution configuration "release|any cpu".
  It was not possible to find any installed .NET Core SDKs
  Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
      https://aka.ms/dotnet-download
##[error]Test1\Server\Server.csproj(0,0): Error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
D:\a\s\Test1\Server\Server.csproj : error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
##[error]Test1\Server\Server.csproj(0,0): Error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Project "D:\a\s\FluidTickets.sln" (1) is building "D:\a\s\Test1\Server\Server.csproj" (2) on node 1 (default targets).
D:\a\s\Test1\Server\Server.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Done Building Project "D:\a\s\Test1\Server\Server.csproj" (default targets) -- FAILED.
...

在 Whosebug 的另一个答案中,我读到了有关添加新变量的内容:

MSBuildSDKsPath = C:\agent\_work\_tool\dotnet\sdk.0.100-rc.1.20452.10\Sdks

但如果我这样做,恢复任务会在构建任务之前失败。所以看起来 SDK 是 'reachable',在某种程度上...
还有其他想法吗?
提前致谢。

将您的 UseDotNet 任务更改为以下内容,以确保 Visual Studio 2019 预览版与 .NET5 预览版结合使用:

- task: UseDotNet@2
  displayName: 'Use .NET 5 SDK (preview)'
  inputs:
    packageType: 'sdk'
    version: '5.0.100-rc.1.20452.10'
    vsVersion: '16.8.0'
    includePreviewVersions: true

供您参考的完整 YAML 管道(这适用于我的 Blazor WASM .Net 5 项目):

pool:
  vmImage: 'ubuntu-latest'

steps:

- task: UseDotNet@2
  displayName: 'Use .NET 5 SDK (preview)'
  inputs:
    packageType: 'sdk'
    version: '5.0.100-rc.1.20452.10'
    vsVersion: '16.8.0'
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  displayName: 'NuGet restore'
  inputs:
    command: 'restore'
    projects: 'MyProject/MyProject.csproj'
    verbosityRestore: 'Normal'

- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    zipAfterPublish: true
    command: publish
    publishWebProjects: false
    projects: 'MyProject/MyProject.csproj'
    arguments: '-c $(Build.Configuration) -o $(Build.ArtifactStagingDirectory) --no-restore'

- task: PublishBuildArtifacts@1
  displayName: 'Publish'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

同样值得注意的是,一旦您将 api 升级为使用 NET 5,您需要进入 Azure 门户 > 应用服务 > 您的 api > 配置 > 常规设置并将堆栈切换到 NET并将 NET 框架版本切换到 NET 5。