Giter VIP home page Giter VIP logo

Comments (7)

Chunwol avatar Chunwol commented on July 24, 2024

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.

MrDave1999 avatar MrDave1999 commented on July 24, 2024

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:

if (dir == null || dir == string.Empty) dir = Directory.GetCurrentDirectory();

from dotnet-env.

rogusdev avatar rogusdev commented on July 24, 2024

I'll take a PR for it if that is all it takes

from dotnet-env.

Chunwol avatar Chunwol commented on July 24, 2024

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.

Chunwol avatar Chunwol commented on July 24, 2024

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.

joostmeijles avatar joostmeijles commented on July 24, 2024

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.

rogusdev avatar rogusdev commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.