I have a dotnet api that I build in azure devops. I have to extract the swagger during the build.
I therefore issue the following command:
- task: CmdLine@2
displayName: 'Generate Swagger'
inputs:
script: |
dotnet new tool-manifest
dotnet tool install --version 6.5.0 Swashbuckle.AspNetCore.Cli
cd Api
set ASPNETCORE_ENVIRONMENT=Development
dotnet swagger tofile --output $(Build.ArtifactStagingDirectory)/swagger.json $(System.DefaultWorkingDirectory)/src/Api/bin/Release/net8.0/Api.dll v1
workingDirectory: '${{ parameters.workingDirectory }}'
The problem is that I have the impression that it launches the application because it looks for my appsettings and once filled, it tries to connect to the BDD.
How do I generate my swagger in a ci?
Load appsettings file in Main method :
IConfiguration Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
.AddEnvironmentVariables()
.Build();