Dirt.Env 1.1.1

dotnet add package Dirt.Env --version 1.1.1
                    
NuGet\Install-Package Dirt.Env -Version 1.1.1
                    
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="Dirt.Env" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dirt.Env" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Dirt.Env" />
                    
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 Dirt.Env --version 1.1.1
                    
#r "nuget: Dirt.Env, 1.1.1"
                    
#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 Dirt.Env@1.1.1
                    
#: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=Dirt.Env&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=Dirt.Env&version=1.1.1
                    
Install as a Cake Tool

Dirt.Env

Dirt.Env is a simple library for working with environment variables in .NET.

Its goal is to provide some convenience and safety around working with environment variables.

Usage

You can use the default constructor of the Env class to get access to the current environment variables.

var env = new Dirt.Env();

This class implements the IEnv interface, which allows accessing the environment variables in a read-only manner through the API of IReadOnlyDictionary<string, string>.

In addition to general dictionary access, the path environment variable can be accessed through the Path property which returns a read-only list.

You can also use the path separation logic on any environment variable by using the GetPathSeparatedValue(string) method.

The path separator of the current system will be used by default, but this can be configured by using the EnvBuilder class.

EnvBuilder

The EnvBuilder class makes it easy to build up an Env instance with custom environment variables.

var env = new EnvBuilder()
    .WithSystemEnvironment()
    .SetVariable("MY_CUSTOM_VARIABLE", "MY_VALUE")
    .Build();

You can also work with the path variable in a natural way. The underlying path variable used and path separator will be managed by the EnvBuilder class.

var env = new EnvBuilder()
    .WithSystemEnvironment()
    .AppendPath("C:\\My\\Path")
    .AppendPath("C:\\My\\OtherPath")
    .Build();

When working with paths, the EnvBuilder class provides three ways it can handle duplicate paths being appended or prepended:

  • IfDuplicatePath.Supersede will remove any duplicate paths from the list before adding the new path. This is the default.
  • IfDuplicatePath.Ignore will always add the path if it is already in the list. This will result in duplicate paths.
  • IfDuplicatePath.Skip will not add the path if it is already in the list.

This enum is located in the Dirt.Environment namespace.

These strategies can be configured with every addition to the builder or set a default. When set in the builder it will only take effect for future additions.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

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.1.1 205 12/24/2025
1.1.0 168 12/8/2024
1.0.1 201 3/17/2024