使用github操作进行部署时更改appsettings中的变量

时间:2020-03-04 08:36:17

标签: c# asp.net azure-web-app-service github-actions

我正在尝试使用github操作部署应用程序。我将我的azure帐户链接到我的github存储库,并创建了以下操作:

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

on:
  push:
    branches:
      - master

jobs:
  build-and-deploy:
    runs-on: ubuntu-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@v1
      with:
        app-name: 'my_app_name'
        slot-name: 'production'
        publish-profile: ${{ secrets.AzureAppService_PublishProfile_xxxxxx }}
        package: ${{env.DOTNET_ROOT}}/myapp 

我的appsettings.json文件中有一些要覆盖的变量,但找不到如何实现的方法。

1 个答案:

答案 0 :(得分:7)

您可以在将工件部署到天蓝色之前添加以下操作。

您可以指定多个文件,通配符条目也支持该文件。

必须使用点分隔的层次结构指定环境变量键。

#substitute production appsettings entries to appsettings json file
- name: App Settings Variable Substitution
  uses: microsoft/variable-substitution@v1
  with:
    files: '${{env.DOTNET_ROOT}}/myapp/appsettings.json'
  env:
    ConnectionStrings.Default: ${{ secrets.some_connection_string }}
    App.ServerRootAddress: ${{ env.SERVER_ROOT_ADDRESS }}

上述操作也可以用于xml和yaml文件更改。