Environments.EnvironmentMappings 1.0.0

dotnet add package Environments.EnvironmentMappings --version 1.0.0
                    
NuGet\Install-Package Environments.EnvironmentMappings -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Environments.EnvironmentMappings" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Environments.EnvironmentMappings" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Environments.EnvironmentMappings" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Environments.EnvironmentMappings --version 1.0.0
                    
#r "nuget: Environments.EnvironmentMappings, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Environments.EnvironmentMappings@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Environments.EnvironmentMappings&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Environments.EnvironmentMappings&version=1.0.0
                    
Install as a Cake Tool

Environments.EnvironmentMappings

Publish NuGet

Environments.EnvironmentMappings provides deterministic environment mapping for .NET applications. It lets you keep real-world environment names (QA, UAT, PreProd, etc.) while mapping them to canonical ASP.NET Core behavior (Development, Staging, Production).

NuGet Package

Package ID: Environments.EnvironmentMappings. Namespaces: Environments.EnvironmentMappings.*. Package metadata is defined in Environments.EnvironmentMappings.nuspec. The changelog is in CHANGELOG.md and each release should update both the package version and releaseNotes. Targets: net6.0 and net10.0.

Core Concepts

  • EnvironmentProfile is the source of truth for environment semantics.
  • IEnvironmentProfileResolver resolves raw environment names into profiles.
  • Extension methods are thin conveniences and rely on resolved profiles.

Default Profiles

The resolver ships with the following defaults. You can override or replace them via DI.

Profile Name Canonical Environment
CDE Development
Development Development
Dev Development
Local Development
Staging Staging
QA Staging
QualityAssurance Staging
UAT Staging
Performance Staging
PreProd Staging
Production Production

Usage

using Environments.EnvironmentMappings.Abstractions;
using Environments.EnvironmentMappings.Extensions;
using Environments.EnvironmentMappings.Models;
using Environments.EnvironmentMappings.Options;

var services = new ServiceCollection();
services.AddEnvironmentProfiles(options =>
{
    options.SetProfile(new EnvironmentProfile("Perf", CanonicalEnvironment.Staging));
    options.UnknownEnvironmentBehavior = UnknownEnvironmentBehavior.UseFallbackCanonicalEnvironment;
    options.FallbackCanonicalEnvironment = CanonicalEnvironment.Production;
});

var provider = services.BuildServiceProvider();
var resolver = provider.GetRequiredService<IEnvironmentProfileResolver>();

var profile = resolver.Resolve("QA");
var isNonProd = profile.IsNonProduction();
var isStaging = profile.IsStaging();
var isQa = profile.IsEnvironment("QA");
var isCanonical = profile.IsEnvironment("Staging");

Environment Variable Resolution

If you're not using IHostEnvironment, you can resolve directly from environment variables. The resolver checks DOTNET_ENVIRONMENT first, then falls back to ASPNETCORE_ENVIRONMENT.

using Environments.EnvironmentMappings.Extensions;

var profile = resolver.ResolveFromEnvironmentVariables();

Canonical Host Environment

If you want ASP.NET Core's built-in environment checks (like IsDevelopment()) to behave according to your profile mappings, you can set the host environment to the canonical value before building the host.

using Environments.EnvironmentMappings.Extensions;

var builder = Host.CreateDefaultBuilder(args)
    .UseCanonicalEnvironmentMappings();

Environment Profile Checks

Environment profiles also expose convenience checks that mirror the host environment extensions. These operate on the profile's canonical environment and can also match the profile name when using IsEnvironment.

var profile = resolver.Resolve("QA");

if (profile.IsStaging())
{
    // Canonical environment check.
}

if (profile.IsEnvironment("QA"))
{
    // Matches the profile name.
}

Host Environment Integration

using Environments.EnvironmentMappings.Abstractions;
using Environments.EnvironmentMappings.Extensions;
using Environments.EnvironmentMappings.Models;
using Microsoft.Extensions.Hosting;

IHostEnvironment hostEnvironment = ...;
IEnvironmentProfileResolver resolver = ...;

var profile = hostEnvironment.GetEnvironmentProfile(resolver);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 355 1/4/2026
0.3.0 133 1/4/2026
0.2.8 126 12/31/2025
0.2.5 121 12/31/2025

1.0.0 release: finalized namespace structure, expanded environment aliases (Dev, Local, Performance), added EnvironmentProfile helpers and XML docs.