Skip to content

Environment variables for .NET Framework 4.7.2 set on a run basis rather than on a project root folder basis #69

Description

@Chunwol

I'm not using NET Core, I'm developing using NET Framework 4.7.2.

The project is using a function called Directory.GetCurrentDirectory() to find the root folder.

NET Framework, the function finds the location where the project was launched, not the root folder of the project.

Because of this, the path changes depending on the execution environment, and when you build with IIS Express in Visual Studio 2022, the root folder is applied as "C:\Program Files\IIS Express" rather than the project folder.

Because of this, putting ".env" in the project root folder doesn't work.

This issue was in the past "dotnet/aspnetcore#4206" and was fixed in Net Core but not in Net Framework.

According to what I checked on https://stackoverflow.com/a/53655514, in NET Framework, you should use System.AppContext.BaseDirectory instead of System.IO.Directory.GetCurrentDirectory() to work properly. At this time, I confirmed that it normally finds the project root folder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions