Asp.net core 3.1 - InProcess on Azure app Service HTTP 错误 500.31 - ANCM 无法找到本机依赖项

Asp.net core 3.1 - InProcess on Azure app Service HTTP Error 500.31 - ANCM Failed to Find Native Dependencies

我已经将我的项目迁移到 asp.net 核心 3.1,但是当我部署到 azure web 应用程序时它无法启动。

显示错误

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies Common solutions to this issue: The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found. Troubleshooting steps: Check the system event log for error messages Enable logging the application process' stdout messages Attach a debugger to the application process and inspect

  <EventData>
            <Data>Could not find 'aspnetcorev2_inprocess.dll'. Exception message:
Invalid runtimeconfig.json [D:\home\site\wwwroot\Flymark.Online.Web.runtimeconfig.json] [D:\home\site\wwwroot\Flymark.Online.Web.runtimeconfig.dev.json]
</Data>
            <Data>Process Id: 23260.</Data>
            <Data>File Version: 13.1.20074.3. Description: IIS ASP.NET Core Module V2. Commit: e81033e094d4663ffd227bb4aed30b76b0631e6d</Data>
        </EventData>

    <EventData>
            <Data>Could not find 'aspnetcorev2_inprocess.dll'. Exception message:
Failed to load the dll from [D:\home\site\wwwroot\hostpolicy.dll], HRESULT: 0x8007007E
An error occurred while loading required library hostpolicy.dll from [D:\home\site\wwwroot\]
</Data>
            <Data>Process Id: 21176.</Data>
            <Data>File Version: 13.1.20074.3. Description: IIS ASP.NET Core Module V2. Commit: e81033e094d4663ffd227bb4aed30b76b0631e6d</Data>
        </EventData>

我正在使用 build.yml

在 azure dev ops 中构建我的应用程序
steps:
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.1.x'

  - task: DotNetCoreCLI@2
    displayName: Restore
    inputs:
      command: restore
      projects: '**/*.csproj'
      vstsFeed: 'a8d40e20-5070-473a-8928-33122e7035b7'


  - script: dotnet tool install --global dotnet-ef 
    displayName: 'dotnet install ef'
    workingDirectory: Source

  - script: dotnet publish -c Release -r win-x64 --self-contained 
    displayName: 'dotnet publish web'
    workingDirectory: Source/Web

  - script: dotnet ef migrations script --idempotent --project Online.Db --startup-project web -o $(Build.ArtifactStagingDirectory)/Online.Db.sql
    displayName: 'Prepare sql scripts'
    workingDirectory: Source

  - task: ArchiveFiles@2
    inputs:
      rootFolderOrFile: 'Source/Web/bin/Release/netcoreapp3.1/win-x64/publish' 
      includeRootFolder: false 
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/Web.zip' 
      replaceExistingArchive: false 

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: Release'
    inputs:
      PathtoPublish: '$(build.artifactstagingdirectory)'

      ArtifactName: Release

    condition: succeededOrFailed()

在 azure dotnet --info returns

.NET Core SDK (reflecting any global.json):
 Version:   3.1.103
 Commit:    6f74c4a1dd

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x86
 Base Path:   D:\Program Files (x86)\dotnet\sdk.1.103\

Host (useful for support):
  Version: 3.1.3
  Commit:  4a9f85e9f8

.NET Core SDKs installed:
  1.1.14 [D:\Program Files (x86)\dotnet\sdk]
  2.1.513 [D:\Program Files (x86)\dotnet\sdk]
  2.2.109 [D:\Program Files (x86)\dotnet\sdk]
  3.1.103 [D:\Program Files (x86)\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.14 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.17 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.8 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.14 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.17 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.8 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.1 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.16 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.13 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.17 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.8 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [D:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

我认为问题在于作为 dotnet 信息 return win10-x86 的位数,但是当我创建新的核心应用程序并从 visual studio 部署时它运行良好。

太疯狂了..我花了一个星期后,问题变成了stdoutLogFile=".\logs\stdout",我做了web.config转换并更改为stdoutLogFile="\?\%home%\LogFiles\stdout"现在可以了

所以 Azure 中的 ANCM 错误似乎从未真正对应于 ANCM 消息。例如,如果它抱怨缺少依赖项,则可能是因为 Startup.cs 中抛出了未处理的异常。是的。

查看“真实”错误的最快方法是尝试 运行 来自 Kudu 的应用程序(Azure 应用程序 -> 开发工具部分 -> 高级工具 -> “Go”,使用浏览器内终端到 运行 MyApp.exe,只需输入其路径并按回车键)。解决 ANCM 错误后,您将看到“应用程序在 localhost:5000 上启动”或类似内容。否则它会显示一个堆栈跟踪,告诉你到底是什么问题。