Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting directory different between envFilePaths and probeForEnv. #47

Open
calvin-furano-dts opened this issue Aug 31, 2023 · 1 comment

Comments

@calvin-furano-dts
Copy link

calvin-furano-dts commented Aug 31, 2023

There's a slightly confusing difference between using envFilePaths and probeForEnv.

When you specify envFilePaths, the paths are relative to the current directory (i.e. Directory.GetCurrentDirectory();). For example if I specify a relative path ..\.env it's one directory up from the current directory.

When you specify probeForEnv, it begins searching from AppContext.BaseDirectory. This isn't usually the same as the current directory. For example:

AppContext.BaseDirectory         => C:\MyApp\MyApp.Web\bin\Debug\net6.0\
Directory.GetCurrentDirectory()  => C:\MyApp\MyApp.Web\

So if I had a file C:\MyApp\.env using probeForEnv wouldn't find it (with the default 4 levels to search), but using the explicit path ..\.env would find it. I found this confusing until I looked at the source code.

@bolorundurowb
Copy link
Owner

bolorundurowb commented Mar 1, 2024

@calvin-furano-dts you raise a good point, but the decision to use AppContext.BaseDirectory was an intentional one to always work from the location of the DLL as that is a consistent and predictable directory when compared with Directory.GetCurrentDirectory().

You can see better explanations of my point here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants