You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an ASP.NET Core Web 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.json and once filled, it tries to connect to the BDD.
I have the impression that it launches the application
That's exactly how it works.
If you have things that you need your app to not do if run in this manner to generate the file, you should add a mechanism to your application to avoid those things when run a certain way, such as setting an environment variable that specifies a value that indicates skipping those operations.
The app has to be run to execute the code to generate your OpenAPI document. If running the application does things you don't want your app to do when run in this context, you'll need to refactor to add the configurability you need to opt-out of whatever those things are.
I have an ASP.NET Core Web 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.json and once filled, it tries to connect to the BDD.
How do I generate my Swagger in CI?
Load appsettings.json 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();
The text was updated successfully, but these errors were encountered: