Directories.Net 1.0.0

.NET 5.0 .NET Standard 2.1
NuGet\Install-Package Directories.Net -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.
dotnet add package Directories.Net --version 1.0.0
<PackageReference Include="Directories.Net" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Directories.Net --version 1.0.0
#r "nuget: Directories.Net, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Directories.Net as a Cake Addin
#addin nuget:?package=Directories.Net&version=1.0.0

// Install Directories.Net as a Cake Tool
#tool nuget:?package=Directories.Net&version=1.0.0

Directories.Net

Introduction

  • a tiny library (12kB) with a minimal API
  • that provides the platform-specific, user-accessible locations
  • for retrieving and storing configuration, cache and other data
  • on Linux, Windows (≥ 7), macOS and BSD

The library provides the location of these directories by leveraging the mechanisms defined by

Platforms

This library is written for .NET, and runs on .NET 6.0 and later.

A version of this library implemented in Rust is provided by directories-rs.

This version is directly based on the Java version.

Usage

Dependency

Add the library as a dependency to your project:

<ItemGroup>
  <PackageReference Include="Directories.Net" Version="1.0.0" />
</ItemGroup>
Example

Library run by user Alice:

using Directories.Net;

ProjectDirectories myProjDirs = ProjectDirectories.From("com", "Foo Corp", "Bar App");
myProjDirs.configDir;
// Lin: /home/alice/.config/barapp
// Mac: /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
// Win: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config

BaseDirectories baseDirs = new BaseDirectories();
baseDirs.executableDir;
// Lin: /home/alice/.local/bin
// Mac: null
// Win: null

UserDirectories userDirs = new UserDirectories();
userDirs.audioDir;
// Lin: /home/alice/Music
// Mac: /Users/Alice/Music
// Win: C:\Users\Alice\Music

Design Goals

  • The directories library is designed to provide an accurate snapshot of the system's state at the point of invocation of new BaseDirectories(), new UserDirectories() or ProjectDirectories.From().
  • This library does not create directories or check for their existence. The library only provides information on what the path to a certain directory should be. How this information is used is a decision that developers need to make based on the requirements of each individual application.
  • This library is intentionally focused on providing information on user-writable directories only. There is no discernible benefit in returning a path that points to a user-level, writable directory on one operating system, but a system-level, read-only directory on another, that would outweigh the confusion and unexpected failures such an approach would cause.
    • ExecutableDir is specified to provide the path to a user-writable directory for binaries.<br/> As such a directory only commonly exists on Linux, it returns null on macOS and Windows.
    • FontDir is specified to provide the path to a user-writable directory for fonts.<br/> As such a directory only exists on Linux and macOS, it returns null Windows.
    • RuntimeDir is specified to provide the path to a directory for non-essential runtime data. It is required that this directory is created when the user logs in, is only accessible by the user itself, is deleted when the user logs out, and supports all filesystem features of the operating system.<br/> As such a directory only commonly exists on Linux, it returns null on macOS and Windows.

Features

BaseDirectories

The intended use-case for BaseDirectories is to query the paths of user-invisible standard directories that have been defined according to the conventions of the operating system the library is running on.

If you want to compute the location of cache, config or data folders for your own application or project, use ProjectDirectories instead.

Field name Value on Linux / BSD / Solaris Value on Windows Value on macOS
HomeDir $HOME {FOLDERID_UserProfile} $HOME
CacheDir $XDG_CACHE_HOME or $HOME/.cache {FOLDERID_LocalApplicationData} $HOME/Library/Caches
ConfigDir $XDG_CONFIG_HOME or $HOME/.config {FOLDERID_ApplicationData} $HOME/Library/Application Support
DataDir $XDG_DATA_HOME or $HOME/.local/share {FOLDERID_ApplicationData} $HOME/Library/Application Support
DataLocalDir $XDG_DATA_HOME or $HOME/.local/share {FOLDERID_LocalApplicationData} $HOME/Library/Application Support
ExecutableDir $XDG_BIN_HOME or $XDG_DATA_HOME/../bin or $HOME/.local/bin null null
PreferenceDir $XDG_CONFIG_HOME or $HOME/.config {FOLDERID_ApplicationData} $HOME/Library/Preferences
RuntimeDir $XDG_RUNTIME_DIR or null null null

UserDirectories

The intended use-case for UserDirectories is to query the paths of user-facing standard directories that have been defined according to the conventions of the operating system the library is running on.

Field name Value on Linux / BSD Value on Windows Value on macOS
HomeDir $HOME {FOLDERID_UserProfile} $HOME
AudioDir XDG_MUSIC_DIR {FOLDERID_Music} $HOME/Music
DesktopDir XDG_DESKTOP_DIR {FOLDERID_Desktop} $HOME/Desktop
DocumentDir XDG_DOCUMENTS_DIR {FOLDERID_Documents} $HOME/Documents
DownloadDir XDG_DOWNLOAD_DIR {FOLDERID_Downloads} $HOME/Downloads
FontDir $XDG_DATA_HOME/fonts or $HOME/.local/share/fonts null $HOME/Library/Fonts
PictureDir XDG_PICTURES_DIR {FOLDERID_Pictures} $HOME/Pictures
PublicDir XDG_PUBLICSHARE_DIR {FOLDERID_Public} $HOME/Public
TemplateDir XDG_TEMPLATES_DIR {FOLDERID_Templates} null
VideoDir XDG_VIDEOS_DIR {FOLDERID_Videos} $HOME/Movies

ProjectDirectories

The intended use-case for ProjectDirectories is to compute the location of cache, config or data folders for your own application or project, which are derived from the standard directories.

Field name Value on Linux / BSD Value on Windows Value on macOS
CacheDir $XDG_CACHE_HOME/<project_path> or $HOME/.cache/<project_path> {FOLDERID_LocalApplicationData}/<project_path>/cache $HOME/Library/Caches/<project_path>
ConfigDir $XDG_CONFIG_HOME/<project_path> or $HOME/.config/<project_path> {FOLDERID_ApplicationData}/<project_path>/config $HOME/Library/Application Support/<project_path>
DataDir $XDG_DATA_HOME/<project_path> or $HOME/.local/share/<project_path> {FOLDERID_ApplicationData}/<project_path>/data $HOME/Library/Application Support/<project_path>
DataLocalDir $XDG_DATA_HOME/<project_path> or $HOME/.local/share/<project_path> {FOLDERID_LocalApplicationData}/<project_path>/data $HOME/Library/Application Support/<project_path>
PreferenceDir $XDG_CONFIG_HOME/<project_path> or $HOME/.config/<project_path> {FOLDERID_ApplicationData}/<project_path>/config $HOME/Library/Preferences/<project_path>
RuntimeDir $XDG_RUNTIME_DIR/<project_path> null null

The specific value of <project_path> is computed by the

ProjectDirectories.From(string qualifier,
                        string organization,
                        string application)

method and varies across operating systems. As an example, calling

ProjectDirectories.From("org"         /*qualifier*/,
                        "Baz Corp"    /*organization*/,
                        "Foo Bar-App" /*application*/)

results in the following values:

Value on Linux Value on Windows Value on macOS
"foobar-app" "Baz Corp/Foo Bar-App" "org.Baz-Corp.Foo-Bar-App"

The ProjectDirectories.FromPath method allows the creation of ProjectDirectories instances directly from a project path. This argument is used verbatim and is not adapted to operating system standards. The use of ProjectDirectories.FromPath is strongly discouraged, as its results will not follow operating system standards on at least two of three platforms. Directories

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net5.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Directories.Net:

Package Downloads
CodeGame.Client

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 312 9/1/2021