Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Loader/EnvLoader.HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private Result<string> GetEnvFilePath(string envFileName)
envFileName = Path.GetFileName(envFileName);
}
else
path = AppContext.BaseDirectory;
path = PathResolver.BaseDirectory;

for (var directoryInfo = new DirectoryInfo(path);
directoryInfo is not null;
Expand Down
18 changes: 18 additions & 0 deletions src/Loader/PathResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace DotEnv.Core;

internal class PathResolver
{
public static string BaseDirectory
{
get
{
// AppContext.BaseDirectory may not be available in all hosting
// environments (e.g. SampSharp/open.mp). Fall back to the current
// working directory when necessary.
if (!string.IsNullOrWhiteSpace(AppContext.BaseDirectory))
return AppContext.BaseDirectory;

return Directory.GetCurrentDirectory();
}
}
}
Loading