Debug, Dev, Release, and Prod in .NET

A recent exchange between coworkers revealed a confusing but important distinction in .NET runtime nomenclature. These folks were looking to reproduce the same behavior on their individual machines, but just couldn’t stick it. One of them was running the application “in Production mode” and the other “with Release build.” The terms “Release” and “Production” seem to go together naturally, similarly with “Debug” and “Development,” but in practice these keywords refer to distinct elements of a running application.

Debug and Release are build configurations which impact code compilation. Applications that were compiled in Debug have less-optimized, lengthier source code you can set breakpoints against, compared to Release which are optimized and more performant. You can pick which configuration to build with in Visual Studio or using the --configuration option in the dotnet CLI. You can write code with #regions that are included or excluded by build config, but it’s mostly ill-advised.

Development and Production are special name-values for what environment a .NET application is running in, drawn from the DOTNET_ENVIRONMENT or (for web) ASPNETCORE_ENVIRONMENT environment variables. These settings are sneaky, since applications will run as Production by default, and for most developers, the actual setting for Development is hidden in a project’s launchsettings.json file instead of as an actual environment variable on their machine. There’s also Staging which doesn’t get as much love typically. While hidden, these are important; influencing what configuration files load, or branching logic outright, like the condition below from a boilerplate Startup.cs:

if (!app.Environment.IsDevelopment())
{
  // do some stuff for dev only
}

So while it’s helpful to use Debug while in development, and important to publish Release-compiled applications to production, these build configurations have no bearing on the actual configuration of your application. For those you must set the appropriate ENVIRONMENT variable to Development or Production.

Hope this helps.

Return