通过 Github Actions Workflow ASP .Net 多文件项目在 Azure 上运行不正确的文件

问题描述 投票:0回答:1

我正在尝试通过 Github 操作将我的 ASP .Net MVC Core Web 应用程序部署到 Azure。在本地主机上运行它时,一切正常,但是当部署(部署过程完美)到 Azure 时,它会显示错误 500。 enter image description here

我已经设置了连接字符串和一切(我猜),我认为我的工作流程可能存在问题。当尝试从 Kudu 检查它并运行我在本地主机上运行的文件时,它工作正常my Web file is the main one

我尝试在工作流程中编写不同的内容,如下所示:

# 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 - instbyden

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest
    
    steps:
      - uses: actions/checkout@v4

      - name: Set up .NET Core
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '7.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@v3
        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 }}
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: .net-app
      
      - name: Login to Azure
        uses: azure/login@v1
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6E7DB23ABB7C46C581EBCFE4FB00E6F3 }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_D582151191524D76A669EB69D9D63985 }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_F9EFD9D768594B54B60D373563613D0F }}

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'instbyden'
          slot-name: 'Production'
          package: .

这是我的 GitHub 项目的链接:https://github.com/gr1gor1ychuk/Hryhoriichuk.University.Instagram

(我尝试检查日志中是否有错误 500,但它们没有用)

asp.net-mvc error-handling azure-web-app-service github-actions workflow
1个回答
0
投票

我尝试了您的代码,做了一些更改,并且能够通过 GitHub 操作将应用程序部署到 Azure 应用服务。

这是我的.yml 文件:

name: Build and deploy ASP.Net Core app to Azure Web App - Dotnetapptest
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.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@v3
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@v3
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'Dotnetapptest'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_7DFA6BD4ADDE43EA98EAC01EEFCA5CD0 }}
package: .

确保在 Azure 应用服务的应用程序设置中正确添加 ClientID 和客户端密钥。

enter image description here

我通过 GitHub 部署了该应用程序。

enter image description here

这是本地输出:

enter image description here

这是部署后的输出:

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.