【问题标题】:Azure CI pipeline for Blazor .NET 5 doesn't workBlazor .NET 5 的 Azure CI 管道不起作用
【发布时间】:2020-10-06 19:52:53
【问题描述】:

我有一个用于 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\1\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\1\s\FluidTickets.sln" (1) is building "D:\a\1\s\Test1\Server\Server.csproj" (2) on node 1 (default targets).
D:\a\1\s\Test1\Server\Server.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Done Building Project "D:\a\1\s\Test1\Server\Server.csproj" (default targets) -- FAILED.
...

在 StackOverflow 的另一个答案中,我读到了有关添加新变量的信息:

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

但是,如果我这样做,那么在构建之前,还原任务就会失败。所以看起来 SDK 在某种程度上是“可访问的”...
还有什么想法吗?
提前致谢。

【问题讨论】:

  • net5 SDK 预览版仅在 Visual Studio 预览版中受支持。在您的 UseDotNet 任务中,您必须指定要使用的 VS 版本
  • 哦,对了,有道理……请问您知道怎么做吗?谢谢。
  • 我的意思是:你说的是 UseDotNet,但我认为你指的是 VSBuild@1 任务,我只能指定“Visual Studio 2019”,而不是确切的版本......跨度>

标签: blazor azure-pipelines-build-task .net-5


【解决方案1】:

将您的 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'

【讨论】:

  • 谢谢Akinzekeel,这是一个很好的建议,虽然现在我有另一个错误:错误:.NET Core SDK 版本 5.0.100-rc.1.20452.10 至少需要 16.8.0 版本微软构建。当前可用的 MSBuild 版本是 16.7.0.37604。
  • 您使用的是哪个构建代理/映像?我的 ubuntu-latest 工作正常
  • 事情变得更糟了。如果我使用 ubuntu-latest,当涉及到 VSBuild@1 任务时,我会收到错误消息:当前操作系统无法运行此任务。这通常意味着该任务仅针对 Windows 编写
  • 好吧,我的错!我的局部变量有问题。现在它工作了,显然! :-) 再次感谢你!!! :-)
  • 你现在可以像这样使用官方版本了: - task: UseDotNet@2 displayName: 'Use .NET 5 SDK' inputs: packageType: 'sdk' version: '5.0.100'
【解决方案2】:

还值得注意的是,一旦您将 api 升级为使用 NET 5,您需要进入 Azure Portal > App Services > Your api > Configuration > General Settings & 将 Stack 切换到 NET 并将 NET 框架版本切换到 NET 5。

【讨论】:

    猜你喜欢
    • 2020-01-09
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 1970-01-01
    • 2021-11-16
    • 2020-05-03
    相关资源
    最近更新 更多