Mat*_*ard 5 azure-web-app-service github-actions
我有一个 GitHub Action,它使用默认的 Microsoft 模板将 ASP.Net Core 应用程序构建到 Azure 应用服务。
在操作的顶部,您可以声明一些环境变量。我将这些设置如下:
name: Build and deploy ASP.Net Core app to an Azure Web App
env:
AZURE_WEBAPP_NAME: (redacted) # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.0' # set this to the .NET Core version to use
Run Code Online (Sandbox Code Playgroud)
我的问题是根文件夹不包含 .csproj 或 .sln 文件。所以这一行是不正确的:AZURE_WEBAPP_PACKAGE_PATH: '.'
我尝试将其更改为AZURE_WEBAPP_PACKAGE_PATH: './FolderName/FolderName'(以及许多其他变体),这是 .csproj 文件所在的位置,但是由于以下错误,构建仍然失败:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
编辑以包含整个 YAML 文件:
name: Build and deploy ASP.Net Core app to an Azure Web App
env:
AZURE_WEBAPP_NAME: (redacted) # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: '../../FolderName/FolderName' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.0' # set this to the .NET Core version to use
on:
push:
branches:
- "master"
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- 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:
permissions:
contents: none
runs-on: windows-latest
needs: build
environment:
name: 'Development'
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: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
Run Code Online (Sandbox Code Playgroud)
小智 2
我遇到了同样的问题,并在这个SO 答案中找到了解决方案,尽管它没有被标记为正确的。
考虑到上述情况,您的 yaml 文件应如下所示:
name: Build and deploy ASP.Net Core app to an Azure Web App
defaults:
run:
working-directory: ./FolderName/FolderName
env:
AZURE_WEBAPP_NAME: (redacted) # set this to the name of your Azure Web App
AZURE_WEBAPP_PACKAGE_PATH: '../../FolderName/FolderName' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '3.0' # set this to the .NET Core version to use
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
719 次 |
| 最近记录: |