Skip to content

Use $HOME/.local/share/Microsoft/User-secrets instead of $HOME/.microsoft/usersecrets/ in unix-like environments. #101012

@ariellourenco

Description

@ariellourenco

Description

This is a classic issue raised in any project. Currently .NET runtime pollutes user $HOME directory by placing an unnecessary folder there:

// For backwards compat, this checks env vars first before using Env.GetFolderPath
 string? appData = Environment.GetEnvironmentVariable("APPDATA");
 string? root = appData                                                                   // On Windows it goes to %APPDATA%\Microsoft\UserSecrets\
    ?? Environment.GetEnvironmentVariable("HOME")                 // On Mac/Linux it goes to ~/.microsoft/usersecrets/
    ?? Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
    ?? Environment.GetEnvironmentVariable(userSecretsFallbackDir);           

This is a common pain for a long time for many people on unix-like platforms. Interestingly, on Windows, the runtime is a good citizen and follow Microsoft recommendations for folder locations, storing user secrets under APPDATA. However, I cannot say the same for unix-like platforms.

Reproduction Steps

To reproduces the problem run the init command for the Secret Manager tool in the project directory.

Expected behavior

Files stored by .NET runtime should follow the XDG Base Directory specification and place user configuration files in $XDG_DATA_HOME/ (default ~/.local/share).

On Mac, we should use ~/Library/Application Support

Actual behavior

As seen on Linux and Mac, .NET runtime leave config files in ~/.microsoft/usersecrets

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

There are a few issues related to this one across Microsoft repos.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions