How do you publish a web app using Azure pipe line?

Deej 21 Reputation points
2021-01-14T17:44:00.133+00:00

In Visual Studio (2019) I can build my app and publish it locally. I can then copy the files manually to my server and everything is fine.

I amusing C# Asp.Net-Mvc Core 2.2, I'll be moving to 3.1 shortly but would like to solve this before I move on.

I'm trying to set up an Azure pipeline as I use VSTS-GIT for my source control. My YAML file is below.

The pipeline runs fine and it uploads files to my server but the website doesn't work and the files that are uploaded aren't the same as the manual method. The error is HTTP Error 500.31 - Failed to load ASP.NET Core runtime, but I think that's a red-herring because the exact same website works perfectly fine if I upload files manually.

I've been at this a while now, reading all sorts of articles and videos but I can't seem to get it to work. I know I am doing something wrong but I don't know what.

I'm struggling to find the right details to do the same thing with Azure Dev Ops, can anyone help, please?

   trigger:
    - local-1

    pool:
      vmImage: 'ubuntu-latest'

    variables:
      buildConfiguration: 'Release'

    steps:
    - script: dotnet build --configuration $(buildConfiguration)
      displayName: 'dotnet build $(buildConfiguration)'

    - task: DotNetCoreCLI@2
      displayName: Publish
      inputs:
        command: publish
        publishWebProjects: True
        arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
        zipAfterPublish: false

    - task: FtpUpload@2
      inputs:
        credentialsOption: 'inputs'
        serverUrl: 'ftp://ftp.xxxxxxx.com/'
        username: 'xxxxxxxxxxxxx'
        password: 'xxxxxxxxxx'
        rootDirectory: '$(Build.ArtifactStagingDirectory)'  
        filePatterns: '**'
        remoteDirectory: '/'
        clean: false
        cleanContents: false
        preservePaths: false
        trustSSL: false
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,997 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. SUNOJ KUMAR YELURU 13,956 Reputation points MVP
    2021-01-16T01:44:22.927+00:00

    @Deej

    Check on the below link it helps on above error.
    Troubleshoot ASP.NET Core on Azure App Service and IIS

    Please don’t forget to Accept the answer and up-vote wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. Krish G 2,326 Reputation points
    2021-01-20T10:47:45.567+00:00

    The error 500.31 happens due to below as mentioned in 500.31 ANCM Failed to Find Native Dependencies, you can find the detailed error in the http response by setting the ASPNETCORE_ENVIRONMENT environment variable to Development.

    ----------------------------------------------------------

    The worker process fails. The app doesn't start.

    The ASP.NET Core Module attempts to start the .NET Core runtime in-process, but it fails to start. The most common cause of this startup failure is when the Microsoft.NETCore.App or Microsoft.AspNetCore.App runtime isn't installed. If the app is deployed to target ASP.NET Core 3.0 and that version doesn't exist on the machine, this error occurs. An example error message follows:

       The specified framework 'Microsoft.NETCore.App', version '3.0.0' was not found.  
         - The following frameworks were found:  
             2.2.1 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]  
             3.0.0-preview5-27626-15 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]  
             3.0.0-preview6-27713-13 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]  
             3.0.0-preview6-27714-15 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]  
             3.0.0-preview6-27723-08 at [C:\Program Files\dotnet\x64\shared\Microsoft.NETCore.App]  
    

    The error message lists all the installed .NET Core versions and the version requested by the app. To fix this error, either:

    • Install the appropriate version of .NET Core on the machine.
    • Change the app to target a version of .NET Core that's present on the machine.
    • Publish the app as a self-contained deployment.

    When running in development (the ASPNETCORE_ENVIRONMENT environment variable is set to Development), the specific error is written to the HTTP response. The cause of a process startup failure is also found in the Application Event Log.

    ------------------------------------------------------------------------------------

    So, it looks like when you are building and publishing from local Visual Studio, the dependencies are satisfied. But when doing that from Azure Pipeline dotnet build, something is missing. It can also happen if the application pool does not have permissions to the site folder.
    Related threads:
    https://stackoverflow.com/questions/65317970/http-error-500-31-failed-to-load-asp-net-core-runtime
    https://stackoverflow.com/questions/61560780/i-keep-getting-http-error-500-31-ancm-failed-to-find-native-dependencies
    https://github.com/dotnet/aspnetcore/issues/14443
    https://stackoverflow.com/questions/58140584/hosting-asp-net-core-3-0-in-azure-http-error-500-31-ancm-failed-to-find-nativ
    https://forums.asp.net/t/2164023.aspx?Need+help+with+resolving+Http+error+500+31+on+IIS
    https://stackoverflow.com/questions/56630477/http-error-500-31-ancm-failed-to-find-native-dependencies-in-iis

    On a side note (not related to this issue), if you deploy to Azure App Service (Web App), use Azure App Service Deploy task instead of FTP upload.

    0 comments No comments