Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a Swagger file using the Swagger command in Azure DevOps with .Net6 and KeyVault, you can follow these steps:

  1. Create a new .Net6 web API project in Visual Studio.
  2. Install the Swagger library by running the following command in the Package Manager Console:

    Install-Package Swashbuckle.AspNetCore

  3. Add the following code to the ConfigureServices method in the Startup.cs file:

    services.AddSwaggerGen(c =>
    {
       c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
    });
    
  4. Add the following code to the Configure method in the Startup.cs file:

    app.UseSwagger();
    app.UseSwaggerUI(c =>
    {
       c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
    });
    
  5. Build and run the project to ensure that the Swagger documentation is generated correctly.

  6. Add the Swagger CLI task to your Azure DevOps pipeline, and configure it as follows:

    • Select the .Net6 SDK version.
    • Specify the path to your Swagger file.
    • Enable the AzureRM Key Vault option and provide the necessary information to connect to your key vault.
  7. Run the pipeline to generate the Swagger file and store it securely in your key vault.