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

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

我有一个用于 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在某种程度上是“可达的”......
还有其他想法吗?
提前致谢。

最佳答案

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

关于blazor - Blazor .NET 5 的 Azure CI 管道不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64232919/

相关文章:

c# - 记录类型 : overriding EqualityContract breaks the equality/hashcode match

javascript - 如何禁用所有浏览器的 razor 组件中使用的 `<InputText type="password">` 字段中显示的建议密码列表

c# - StateHasChanged 用于特定组件,而不是重新渲染页面中的所有组件

c# - 为什么 Entity Framework Core 迁移需要 .NET Core 2.x?

azure - 如何在 Azure DevOps 管道中管理构建工件?

MSBuild 属性作为 VSTS 生成定义中的变量

c# - 使用 .NET 5 Azure Functions 中的 Content-Type multipart/form-data 从 HttpRequestData 获取 POST 参数

javascript - 为什么我的 blazor.server.js 之后无法加载任何 js?

asp.net-core - Blazor 应用程序中的数据检索返回空数组

git - Azure 管道 : I am getting fatal: could not read Username for 'https://github.com' : terminal prompts disabled