我有一个用于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]Test1ServerServer.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:a1sTest1ServerServer.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]Test1ServerServer.csproj(0,0): Error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Project "D:a1sFluidTickets.sln" (1) is building "D:a1sTest1ServerServer.csproj" (2) on node 1 (default targets).
D:a1sTest1ServerServer.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
Done Building Project "D:a1sTest1ServerServer.csproj" (default targets) -- FAILED.
...
在StackOverflow中的另一个答案中,我读到了关于添加一个新变量的内容:
MSBuildSDKsPath = C:agent_work_tooldotnetsdk5.0.100-rc.1.20452.10Sdks
但如果我这样做,那么在构建任务之前,恢复任务就会失败。因此,看起来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'
同样值得注意的是,一旦您将api升级为使用NET 5,就需要进入Azure Portal>应用服务>您的api>配置>常规设置&将Stack切换到NET,并将NET框架版本切换到NET 5。