Dirt.Env
1.1.1
dotnet add package Dirt.Env --version 1.1.1
NuGet\Install-Package Dirt.Env -Version 1.1.1
<PackageReference Include="Dirt.Env" Version="1.1.1" />
<PackageVersion Include="Dirt.Env" Version="1.1.1" />
<PackageReference Include="Dirt.Env" />
paket add Dirt.Env --version 1.1.1
#r "nuget: Dirt.Env, 1.1.1"
#:package Dirt.Env@1.1.1
#addin nuget:?package=Dirt.Env&version=1.1.1
#tool nuget:?package=Dirt.Env&version=1.1.1
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.Supersedewill remove any duplicate paths from the list before adding the new path. This is the default.IfDuplicatePath.Ignorewill always add the path if it is already in the list. This will result in duplicate paths.IfDuplicatePath.Skipwill 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 | Versions 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. |
-
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.