我有一个使用GitHub操作部署到Azure应用服务的.NET6Web API.
我的Web API包含3个应用程序设置文件:
-
Appsettings.json
-
Appsettings.development.json
-
Appsettings.production.json
据我所知,这些文件通常在本地用于开发和测试目的.
当部署Web应用程序时,它会正确运行并读取应用程序设置中的所有值(以某种方式).然而,配置设置中Azure门户中的"应用程序设置"为空.这让我感到困惑,因为我找不到这些应用程序设置是从哪里读取的.
这是我的GitHub行动YAML:
name: API CI/CD
env:
AZURE_WEBAPP_NAME: test # 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: '6.0' # set this to the .NET Core version to use
on:
push:
branches: [ "main" ]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-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 Test.Api -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: ubuntu-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: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
这是我的程序.cs:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.RegisterApiVersioning();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.RegisterOptions(builder.Configuration);
builder.Services.RegisterServices(builder.Configuration);
builder.Services.RegisterSwagger();
var app = builder.Build();
app.UseCors(maksCorsPolicy);
app.ConfigureSwagger();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.UseMiddleware<ExceptionMiddleware>();
app.Run();
I tried to change a value in my Appsettings.production.json, and it was taken into account when I deployed. This confused me even more since I still can't see any app setting on the Azure Portal, but the application is finding it.
我试着在GitHub和我的应用程序服务上搜索是否有任何配置告诉我的应用程序读取这些JSON文件没有任何运气.
我希望我的应用程序找不到这些应用程序设置.
任何解释都将不胜感激.