-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Environments article overhaul #36022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR completely overhauls the ASP.NET Core environments documentation article to improve its organization, add new content for Docker scenarios, and modernize the guidance. The update addresses two GitHub issues (#35807 and #31962) by restructuring the content with a more logical flow and adding comprehensive Docker environment configuration guidance.
Key changes include:
- Restructured the article with a clearer outline focusing on environments, control mechanisms, and setting approaches
- Added comprehensive Docker guidance (Dockerfile, Docker Compose, docker run, environment files)
- Consolidated versioned content while maintaining support for Startup class patterns
- Updated Azure App Service guidance to reference external documentation
|
||
:::moniker-end | ||
The Production environment is configured to maximize security, performance, and app reliability. Some common settings that differ from the Development environment include: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This revision makes it sound like the framework handles these production configuration changes, but I think most of them are up to the app developer to handle. Can we make it clearer that this is an example list of production concerns that the developer may want to address, not a list of things the framework automatically does?
* Client-side resources are bundled, minified, and potentially served from a CDN. | ||
* Diagnostic error pages disabled. | ||
* Friendly error pages enabled. | ||
* Production [logging](xref:fundamentals/logging/index) and monitoring enabled. For example, using [Application Insights](/azure/application-insights/app-insights-asp-net-core). | ||
When using [Visual Studio Code](https://code.visualstudio.com/), set the `ASPNETCORE_ENVIRONMENT` environment variable in the `.vscode/launch.json` in the `env` section, along with any other environment variables set in the section: | ||
|
||
## Set the environment by setting an environment variable | ||
```json | ||
"env": { | ||
"ASPNETCORE_ENVIRONMENT": "Staging", | ||
... | ||
}, | ||
``` | ||
|
||
It's often useful to set a specific environment for testing with an environment variable or platform setting. If the environment isn't set, it defaults to `Production`, which disables most debugging features. The method for setting the environment depends on the operating system. | ||
The `.vscode/launch.json` file is only used by Visual Studio Code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using launch.json isn't necessary with C# Dev Kit. C# Dev Kit in Visual Studio Code will pick up the available launch profiles from your launchSettings.json file.
|
||
When the host is built, the last environment setting read by the app determines the app's environment. The app's environment can't be changed while the app is running. | ||
## Set the environment with an environment variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't think we need to be documenting how to set an environment variable on various platforms, like Windows, macOS, and Linux. I'm ok keeping some pointers on how to do it for App Service, IIS, Docker, and dotnet run
, although I'd prefer those pointers to mostly be links to the docs for the corresponding service to tech.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! Some feedback.
@danroth27 ... Thanks! I'll get the article updated in the morning and ping u. Then, Javier after you, followed by Tom. |
Co-authored-by: Daniel Roth <[email protected]>
Fixes #35807
Fixes #31962
Startup
class magic ✨ ... It has fallen out of favor in templates, but that's all fully supported AFAIK today and for the future ... and still could be rather helpful if an app has a lot of custom environment code deltas to deal with. Therefore, I'm resurfacing it in the latest guidance. It's at the very bottom of the article, so it's out of the way. My guess is that some devs would still like to use these approaches. I'm 👂 for feedback on that direction. Do you want me to go back to versioning it out at .NET 6?The initial outline for the article on the PR ...
dotnet run
)launchSettings.json
)docker run
commandStartup
class and methodsIWebHostEnvironment
into theStartup
classStartup
class conventionsStartup
class method conventionsInternal previews