Change variables in appsettings when deploying with github actions(使用 github 操作部署时更改 appsettings 中的变量)
问题描述
我正在尝试使用 github 操作部署应用程序.我将我的 azure 帐户链接到我的 github 存储库,并创建了以下操作:
I am trying to deploy an app with github actions. I linked my azure account to my github repository and the following actions has been created:
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 文件中有一些想要覆盖的变量,但我不知道该怎么做.
I have some variables in my appsettings.json file that I want to overwrite, but I don't find how to do it.
推荐答案
您可以在将工件部署到 azure 之前添加以下操作.
You may add the following action prior to deploying the artifacts to azure.
您可以指定多个文件,它也支持通配符条目.
You can specify multiple files and it is supported with wildcard entries too.
环境变量键必须用点分隔的层次结构指定.
The environment variable key must be specified with dot separated heirarchy.
#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文件的更改.
The above action can be used for xml and yaml file changes too.
这篇关于使用 github 操作部署时更改 appsettings 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 github 操作部署时更改 appsettings 中的变量
				
        
 
            
        基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
 - 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
 - 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
 - 全局 ASAX - 获取服务器名称 2022-01-01
 - 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
 - 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
 - 首先创建代码,多对多,关联表中的附加字段 2022-01-01
 - 错误“此流不支持搜索操作"在 C# 中 2022-01-01
 - 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
 - 如何动态获取文本框中datagridview列的总和 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				