Azure CI管道用于Blazor .NET 5无法正常工作

8

我有一个现有的Azure CI管道,用于WebAssembly Blazor应用程序,它与.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。 - Akinzekeel
哦,好的,这很有道理... 你能告诉我怎么做吗?谢谢。 - Andrea
我的意思是:你说使用UseDotNet,但我认为你指的是VSBuild@1任务,在那里我只能指定“Visual Studio 2019”,而不能指定确切的版本... - Andrea
2个回答

5

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

- 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至少需要MSBuild版本16.8.0。当前可用的MSBuild版本为16.7.0.37604。 - Andrea
你正在使用哪个构建代理/镜像?我的在 ubuntu-latest 上可以正常工作。 - Akinzekeel
事情变得更糟了。如果我使用ubuntu-latest,当涉及到VSBuild@1任务时,我会收到错误消息:当前操作系统无法运行此任务。这通常意味着该任务仅适用于Windows。 - Andrea
1
好的,我的错!我的本地变量出了问题。现在它似乎可以工作了! :-) 再次感谢您!!! :-) - Andrea
1
现在您可以这样使用官方版本:
  • task: UseDotNet@2 displayName: '使用 .NET 5 SDK' inputs: packageType: 'sdk' version: '5.0.100'
- iBobb
显示剩余6条评论

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接