.NET 6.0
.NET 6.0

We upgraded an Azure .NET web app to use .NET 6.0 instead of 4.6.2, in itself something of a task for this app. But when we then tried to deploy it to Azure, GitHub failed on the build with dotnet stage:

C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\sdk\3.1.102\Microsoft.Common.CurrentVersion.targets(1175,5): error MSB3644: The reference assemblies for .NETFramework,Version=v6.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks 

So this is clearly a problem with the deployment .yml, since we changed the project, but this yml needs updating!

First things first, have you remembered to change the target in Azure?

Next, we can simply ask Azure to update the build file for us on GitHub.

Here’s the docs: https://learn.microsoft.com/en-us/azure/app-service/deploy-continuous-deployment?tabs=github#disable-continuous-deployment

We have to disconnect, then reconnect again. When we do this we’ll be offered a choice of updating the existing build file on GitHub, and we can say yes.

Once this is all done your build will immediately be triggered so be warned of that!

If you are interested what the difference in the yml is

before:

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - project-name

on:
  push:
    branches:
      - develop

jobs:
  build-and-deploy:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@master

    - name: Set up .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '3.1.102'

    - name: Build with dotnet
      run: dotnet build --configuration Release

    - name: dotnet publish
      run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

    - name: Deploy to Azure Web App
      uses: azure/webapps-deploy@v2
      with:
        app-name: 'project-name'
        slot-name: 'production'
        publish-profile: ${{ secrets.AzureAppService_PublishProfile_longhash }}
        package: ${{env.DOTNET_ROOT}}/myapp 

And after:

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - project-name

on:
  push:
    branches:
      - develop
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up .NET Core
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '6.0.x'
          include-prerelease: true

      - name: Build with dotnet
        run: dotnet build --configuration Release

      - name: dotnet publish
        run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: .net-app
          path: ${{env.DOTNET_ROOT}}/myapp

  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: .net-app

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'project-name'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_longhash }}
          package: .
Last modified: April 24, 2023

Author

Comments

Write a Reply or Comment

Your email address will not be published.