dotnet / dotnet/aspnetcore

`dotnet user-secrets` environment detection faulty

Open
#55,912 0 comments 0 reactions 0 assignees View on GitHub
area-commandlinetools
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Related, but not duplicate of: https://github.com/dotnet/aspnetcore/issues/52746

My setup is like this:
1. Wsl2 up & running
2. Repositories are checkout out within wsl under `/home/user/repos/project1`
3. Opening the project through Visual Studio with explorer.exe on path: `\\wsl.localhost\Ubuntu-22.04\home\user\repos\project1`

As visual studio is coming from windows it loads the Windows environment variable and as stated [here](https://github.com/dotnet/aspnetcore/issues/52746#issuecomment-1853092737) and [here](https://source.dot.net/#Microsoft.Extensions.Configuration.UserSecrets/PathHelper.cs,62)

it first loads the environment variable `APPDATA` and then continues to check other variables if `APPDATA` returned `null`

Since `APPDATA` is always filled on Windows per default it falls back on this variable and in turn fails to open the secrets.json file

![image](https://github.com/dotnet/aspnetcore/assets/3918517/fe22dba8-fec6-48dd-a727-f17ae7b3bd60)

### Expected Behavior

I'd like to run the project from my wsl drive (through a network location) since wsl is a lot faster.

I think a better approach would be to check the location of the current loaded project and then based on that determine where to load the `secrets.json` file from

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with Microsoft.Extensions.Configuration.UserSecrets/PathHelper.cs at the linked source location, then inspect how APPDATA and the other environment variables are selected. Reproduce the WSL2 project opened through Visual Studio if possible, and confirm that secrets.json is resolved from the project’s WSL location rather than the Windows APPDATA path.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.