diff --git a/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md b/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md index 8af31a98ba3e..7ca47477dc29 100644 --- a/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md +++ b/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md @@ -5,7 +5,7 @@ author: wadepickett description: Learn how to generate and customize OpenAPI documents in an ASP.NET Core app. monikerRange: '>= aspnetcore-6.0' ms.author: wpickett -ms.date: 08/19/2026 +ms.date: 09/04/2026 uid: fundamentals/openapi/aspnetcore-openapi --- # Generate OpenAPI documents @@ -294,6 +294,26 @@ Some apps may be configured to emit multiple OpenAPI documents. Multiple OpenAPI ``` +:::moniker-end + +:::moniker range=">= aspnetcore-11.0" + +#### Select the app environment + +Starting in .NET 11, set the `OpenApiGenerationEnvironment` property to select the app environment used during build-time OpenAPI document generation. The property sets the host's environment for the generation process, equivalent to setting the `ASPNETCORE_ENVIRONMENT` or `DOTNET_ENVIRONMENT` environment variable: + +```xml + + Development + +``` + +Selecting the environment enables environment-specific configuration, such as settings from `appsettings.Development.json`, and environment-dependent document transformations to affect the generated document. The property doesn't change the environment used when the app runs normally. + +:::moniker-end + +:::moniker range=">= aspnetcore-10.0" + ### Customize runtime behavior during build-time document generation Build-time OpenAPI document generation functions by launching the apps entrypoint with a mock server implementation. A mock server is required to produce accurate OpenAPI documents because all information in the OpenAPI document can't be statically analyzed. Because the apps entrypoint is invoked, any logic in the apps startup is invoked. This includes code that injects services into the [DI container](xref:fundamentals/dependency-injection) or reads from configuration. In some scenarios, it's necessary to restrict the code paths when the app's entry point is invoked from build-time document generation. These scenarios include: diff --git a/aspnetcore/release-notes/aspnetcore-11.md b/aspnetcore/release-notes/aspnetcore-11.md index 296d16e72b04..6049a9b3b4c1 100644 --- a/aspnetcore/release-notes/aspnetcore-11.md +++ b/aspnetcore/release-notes/aspnetcore-11.md @@ -4,7 +4,7 @@ ai-usage: ai-assisted author: wadepickett description: Learn about the new features in ASP.NET Core in .NET 11. ms.author: wpickett -ms.date: 08/26/2026 +ms.date: 09/04/2026 uid: aspnetcore-11 --- # What's new in ASP.NET Core in .NET 11 @@ -69,6 +69,8 @@ This section describes new features for OpenAPI. [!INCLUDE[](~/release-notes/aspnetcore-11/includes/openapi-server-sent-events-preview-7.md)] +[!INCLUDE[](~/release-notes/aspnetcore-11/includes/openapi-generation-environment.md)] + ## Authentication and authorization This section describes new features for authentication and authorization. diff --git a/aspnetcore/release-notes/aspnetcore-11/includes/openapi-generation-environment.md b/aspnetcore/release-notes/aspnetcore-11/includes/openapi-generation-environment.md new file mode 100644 index 000000000000..bc547a03d938 --- /dev/null +++ b/aspnetcore/release-notes/aspnetcore-11/includes/openapi-generation-environment.md @@ -0,0 +1,15 @@ +### Select an environment for build-time OpenAPI document generation + +Build-time OpenAPI document generation supports selecting the app environment with the `OpenApiGenerationEnvironment` MSBuild property. The property sets the host's environment for the generation process, equivalent to setting the `ASPNETCORE_ENVIRONMENT` or `DOTNET_ENVIRONMENT` environment variable. Environment-specific configuration and document transformations can therefore affect the generated OpenAPI document without requiring the environment variable to be set before running `dotnet build`. + +Set the property in the project file: + +```xml + + Development + +``` + +For more information, see . + +Thank you [@ldsenow](https://github.com/ldsenow) for this contribution!