Comments (7)
Fortunately, it can be used in Net Framework by temporarily using it as follows.
using (Stream stream = File.OpenRead($"{System.AppContext.BaseDirectory}.env"))
{
DotNetEnv.Env.Load(stream);
}
from dotnet-env.
But this error only occurs when using ASP.NET with .NET Framework? Because I just tested the Directory.GetCurrentDirectory()
method in a console application with .NET Framework 4.7.2 and it does return the correct path.
I just tested that the System.AppContext.BaseDirectory
property also works in .NET Core.
I am not so sure but I think the solution would be to remove GetCurrentDirectory
method and replace it with AppContext.BaseDirectory
property:
dotnet-env/src/DotNetEnv/Env.cs
Line 29 in a47e667
from dotnet-env.
I'll take a PR for it if that is all it takes
from dotnet-env.
It seems to happen when using ASP.net together.
"https://docs.microsoft.com/en-us/dotnet/api/system.appcontext.basedirectory"
When I checked, the function supports most versions and it normally loads the default directory file path, so it would be better to change it to the corresponding function.
from dotnet-env.
When using xamarin-android, there is an issue that the function returns NULL. I can't write in detail because I don't have time right now, but if you check the attached issue, there is a solution.
[xamarin-android](xamarin/xamarin-android#3489)
from dotnet-env.
Having the same problem with a ASP.Net Core and Console application within the same solution that uses 1 common .env file.
Using DotNetEnv.Env.TraversePath().Load();
as workaround for now in the ASP.NET project.
from dotnet-env.
I did make this change as it sounds appropriate (I can imagine an app changing the current directory before loading this and ending up in the wrong place anyway). That said, if at any time anyone feels that they want the old behavior, or are having trouble, this is already quite easy to work around, since the first arg to Load
is a file path -- relative or absolute. So just do this: DotNetEnv.Env.Load($"{Directory.GetCurrentDirectory()}.env")
(or whatever your .env file should be called) and that should give you the old behavior back.
from dotnet-env.
Related Issues (20)
- Parse ${ENV_VAR} in env_file HOT 2
- .env.local support HOT 5
- Not compatible with Kubernetes .env HOT 3
- Failure to parse on $ HOT 2
- Not installing on .NET 4.5.2 HOT 3
- Is there support for hierarchical settings? HOT 2
- how to use .env file in production? HOT 1
- Fails to parse when environment file has dash (-) HOT 9
- Not Able to read env variables for project type .NET Framework 4.7.2 HOT 2
- Make change to README file HOT 7
- Creating a IConfigurationBuilder method extension for environment variables HOT 5
- Env file not loading HOT 3
- Vulnerability issue v2.3.0 HOT 1
- Suggestion: Defaults Are Unexpected
- Add readme to nuget package HOT 1
- 2.4.0 Doesn't Work - Fails to Load .env HOT 19
- Encryption HOT 1
- Transitive Dependency System.Net.Http 4.3.0 contains vulnerabilities according to Checkmarx HOT 3
- Denial of Service (DoS) - v2.5.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnet-env.