首页 > 解决方案 > Azure App Service Linux Web App:找不到任何已安装的 .NET Core SDK

问题描述

我正在尝试在 Azure 应用服务 (Linux) 上发布一个小型 .NET Core 3.1 Web 应用,但该应用无法启动。

无论我是使用 Visual Studio 还是 Azure DevOps 发布,我的 Linux Azure App Service 都会出现以下错误(顺便说一句,它已经包含其他两个应用程序):

2021-06-23T22:19:47.102376527Z   _____
2021-06-23T22:19:47.102415627Z   /  _  \ __________ _________   ____
2021-06-23T22:19:47.102422327Z  /  /_\  \___   /  |  \_  __ \_/ __ \
2021-06-23T22:19:47.102426627Z /    |    \/    /|  |  /|  | \/\  ___/
2021-06-23T22:19:47.102430627Z \____|__  /_____ \____/ |__|    \___  >
2021-06-23T22:19:47.102434927Z         \/      \/                  \/
2021-06-23T22:19:47.102438927Z A P P   S E R V I C E   O N   L I N U X
2021-06-23T22:19:47.102442827Z
2021-06-23T22:19:47.102446327Z Documentation: http://aka.ms/webapp-linux
2021-06-23T22:19:47.102449927Z Dotnet quickstart: https://aka.ms/dotnet-qs
2021-06-23T22:19:47.102453427Z ASP .NETCore Version: 3.1.13
2021-06-23T22:19:47.102457227Z Note: Any data outside '/home' is not persisted
2021-06-23T22:19:47.307988432Z Running oryx create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -defaultAppFilePath /defaulthome/hostingstart/hostingstart.dll     -bindPort 8080 -userStartupCommand 'dotnet WebApplication1.dll'
2021-06-23T22:19:47.378242802Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2021-06-23T22:19:47.382799606Z Could not find operation ID in manifest. Generating an operation id...
2021-06-23T22:19:47.382816206Z Build Operation ID: 7f48597c-0791-46e5-bffd-b0007d8b27b7
2021-06-23T22:19:49.335414280Z Writing output script to '/opt/startup/startup.sh'
2021-06-23T22:19:49.567879341Z Running user provided startup command...
2021-06-23T22:19:49.610748271Z A compatible installed .NET Core SDK for global.json version [3.1.409] from [/home/site/wwwroot/global.json] was not found
2021-06-23T22:19:49.610783071Z Install the [3.1.409] .NET Core SDK or update [/home/site/wwwroot/global.json] with an installed .NET Core SDK:
2021-06-23T22:19:49.610825071Z   It was not possible to find any installed .NET Core SDKs
2021-06-23T22:19:49.610829471Z   Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
2021-06-23T22:19:49.610835971Z       https://aka.ms/dotnet-download
2021-06-23T22:19:50.944Z ERROR - Container procoding-me_0_8935305e for site procoding-me has exited, failing site start
2021-06-23T22:19:50.961Z ERROR - Container procoding-me_0_8935305e didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2021-06-23T22:19:50.978Z INFO  - Stopping site procoding-me because it failed during startup.```

我尝试再次在 azure 上创建 web 应用程序,甚至尝试发布其他应用程序的相同代码,并且出现同样的问题。

有人暗示这个问题的原因吗?

标签: c#linuxazureasp.net-coreazure-web-app-service

解决方案


因此,经过一整天的尝试来解决这个问题,我设法发布并应用到一个运行 linux 的应用服务。我正在使用位于“共享”资源组中的应用服务计划(Linux,B1),因为我想在其上运行多个应用。我还在使用 Bicep 部署基础设施,管道是 yaml。

问题似乎在于,当我通过 Azure DevOps 部署应用程序时,它将应用程序存档嵌套在另一个 zip 文件中。应用程序 zip 文件必须是应用程序中的根文件夹,除非您下载在应用程序服务本身中执行的文件,否则并不明显。

是的,我也在这里使用自包含版本的部署。你可以在这里阅读更多关于它的信息。除非我从 Visual Studio 2022 发布了应用程序,否则我使用依赖于框架的方式没有成功。

所以,最后,这里是让这件事对我有用的片段:

azure-pipelines.yaml - 构建阶段

- task: DotNetCoreCLI@2
    inputs:
      command: 'publish'
      projects: '**/*Api.csproj'
      arguments: '--configuration $(buildConfiguration) -r linux-x64 --self-contained true --output $(Build.ArtifactStagingDirectory)'
      modifyOutputPath: false
      publishWebProjects: false
      zipAfterPublish: true
    displayName: 'Dotnet Publish'

  - task: PublishBuildArtifacts@1
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)' 
      ArtifactName: drop

azure-pipelines.yaml - 部署阶段

- task: AzureRmWebAppDeployment@4
              inputs:
                azureSubscription: '$(azureSubscription)'
                appType: webAppLinux
                WebAppName: '$(output_appServiceName)'
                packageForLinux: '$(Pipeline.Workspace)/**/a.zip' #Since we are not specifying the folder name in the steps prior, the folder will be called just a.zip, this is fine since the deployment is going to rename it any way in the app service file system anyway(in Kudu)

Bicep 中的应用服务资源

 resource appService 'Microsoft.Web/sites@2021-01-01' = {
  name: '${serviceName}-${environment}-app'
  location: resourceGroup().location
  kind: 'app'
  properties: {
    serverFarmId: planId
    
    siteConfig: {
      alwaysOn: true
      http20Enabled: true
      linuxFxVersion: 'DOTNETCORE|5.0'
      appSettings: [
        {
          name: 'WEBSITE_RUN_FROM_PACKAGE'
          value: '1'
        }
      ]
    }
  }
}

希望这可以帮助。

PS 在应用服务 (Kudu) 中存在“损坏”的 zip 文件可能会导致应用失败。我建议遇到此问题的人要么从 wwwroot 删除所有文件,要么干脆删除应用服务资源并从头开始部署它,以确保它可以正常启动。


推荐阅读