Azure 发布管道发布到 NetCore 3.1 linux 应用程序服务失败,退出代码为 145 - 'Not possible to find any .NET Core SDKs' 在日志中

Azure release pipeline publish to NetCore 3.1 linux app service fails with exit code 145 - 'Not possible to find any .NET Core SDKs' in log

我正在发布一个 .net core 3.1 应用程序,该应用程序保存在 Azure DevOps 存储库中,构建在构建管道中并发布到 Azure Linux Web 应用程序服务容器。整个过程似乎进展顺利,根据应用服务中的部署 blade,部署成功。

预期结果

我希望在访问 public URL 时看到我部署的网站。

实际结果

相反,我看到新的主机页面显示 "Hey, .NET Core developers! Your app service is up and running. Time to take the next step and deploy your code"。

附加信息

应用服务似乎正在启动默认应用,因为它在启动我发布的应用时遇到问题。

我在应用服务通用配置中指定的启动命令是:

dotnet "SmartSAR.dll"

应用服务启动日志

2020-04-18 07:39:27.802 INFO  - Container smartsar_0_36ea601f for site smartsar initialized successfully and is ready to serve requests.
2020-04-18T07:39:25.664749049Z   _____
2020-04-18T07:39:25.664775249Z   /  _  \ __________ _________   ____
2020-04-18T07:39:25.664780549Z  /  /_\  \___   /  |  \_  __ \_/ __ \
2020-04-18T07:39:25.664799849Z /    |    \/    /|  |  /|  | \/\  ___/
2020-04-18T07:39:25.664803949Z \____|__  /_____ \____/ |__|    \___  >
2020-04-18T07:39:25.664808049Z         \/      \/                  \/
2020-04-18T07:39:25.664811949Z A P P   S E R V I C E   O N   L I N U X
2020-04-18T07:39:25.664815749Z
2020-04-18T07:39:25.664819349Z Documentation: http://aka.ms/webapp-linux
2020-04-18T07:39:25.664823149Z Dotnet quickstart: https://aka.ms/dotnet-qs
2020-04-18T07:39:25.664826849Z ASP .NETCore Version: 3.1.0
2020-04-18T07:39:25.664830549Z Note: Any data outside '/home' is not persisted
2020-04-18T07:39:25.727133075Z Running oryx -appPath /home/site/wwwroot -output /opt/startup/startup.sh -defaultAppFilePath /defaulthome/hostingstart/hostingstart.dll     -bindPort 8080 -userStartupCommand 'dotnet "SmartSAR.dll"'
2020-04-18T07:39:25.730817476Z Oryx Version: 0.2.20200114.13, Commit: 204922f30f8e8d41f5241b8c218425ef89106d1d, ReleaseTagName: 20200114.13
2020-04-18T07:39:25.737275979Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2020-04-18T07:39:25.737697979Z Could not find operation ID in manifest. Generating an operation id...
2020-04-18T07:39:25.738149780Z Build Operation ID: 6b038e35-4bdc-4c95-ba56-af4ed38e0ce0
2020-04-18T07:39:26.610476848Z Writing output script to '/opt/startup/startup.sh'
2020-04-18T07:39:27.105207557Z Running user provided startup command...
2020-04-18T07:39:27.112012760Z   It was not possible to find any installed .NET Core SDKs
2020-04-18T07:39:27.112467060Z   Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
2020-04-18T07:39:27.112892061Z       https://aka.ms/dotnet-download
2020-04-18T07:39:27.113473661Z WARNING: Startup command execution failed with exit code 145
2020-04-18T07:39:27.113786261Z Running the default application instead...
2020-04-18T07:39:27.447628502Z Hosting environment: Production
2020-04-18T07:39:27.448410002Z Content root path: /defaulthome/hostingstart/
2020-04-18T07:39:27.449102503Z Now listening on: http://[::]:8080

构建管道 YAML

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: UseDotNet@2 
  displayName: ".NET Core 3.1.x"
  inputs:
    version: '3.1.x'
    packageType: sdk
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1

生成的工件是一个包含 WebApp.zip 部署文件(以及相关文件)的 drop。

据我所知,我需要启动的正在生成的 dll 是 SmartSAR.dll。来自构建日志:

Building target "_CopyOutOfDateSourceItemsToOutputDirectory" partially, because some output files are out of date with respect to their input files.
  Copying file from "d:\a\s\SmartSAR\obj\Release\netcoreapp3.1\SmartSAR.exe" to "d:\a\s\SmartSAR\bin\Release\netcoreapp3.1\SmartSAR.exe".
CopyFilesToOutputDirectory:
  Copying file from "d:\a\s\SmartSAR\obj\Release\netcoreapp3.1\SmartSAR.dll" to "d:\a\s\SmartSAR\bin\Release\netcoreapp3.1\SmartSAR.dll".
  SmartSAR -> d:\a\s\SmartSAR\bin\Release\netcoreapp3.1\SmartSAR.dll
  Copying file from "d:\a\s\SmartSAR\obj\Release\netcoreapp3.1\SmartSAR.pdb" to "d:\a\s\SmartSAR\bin\Release\netcoreapp3.1\SmartSAR.pdb".

您是否将 Azure Web 应用的 general settings 堆栈 属性 设置为 .NET Core?

问题是我使用了为构建管道生成的默认 YAML,但我没有注意到它针对的是 Windows 构建映像! (怪睡眠不足。)

这是我用于最终工作管道的 YAML:

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:

    - task: UseDotNet@2 
      displayName: ".NET Core 3.1.x"
      inputs:
        version: '3.1.x'
        packageType: sdk
    - script: dotnet build --configuration $(buildConfiguration)
      displayName: 'dotnet build $(buildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: "Test"
      inputs:
        command: test
        projects: '**/*tests/*.csproj'
        arguments: '--configuration $(buildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: "Publish"
      inputs:
        command: 'publish'
        publishWebProjects: true
        arguments: '-r linux-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
        zipAfterPublish: true

    - task: PublishBuildArtifacts@1
      displayName: "Upload Artifacts"
      inputs:
        pathtoPublish: '$(Build.ArtifactStagingDirectory)' 
        artifactName: 'WebApp'