8000 Set runtime configuration values containing the entry-point file path and directory when running file-based apps · Issue #49184 · dotnet/sdk · GitHub
[go: up one dir, main page]

Skip to content
Set runtime configuration values containing the entry-point file path and directory when running file-based apps #49184
@DamianEdwards

Description

@DamianEdwards

UPDATE: See comment after this for latest approach.

When running a file-based app via dotnet run app.cs, there is no way to get the path of the file being executed. This makes it difficult to discover files relative to the application entry-point file. Doing file-based operations relative to the entry-point file is common in script scenarios, e.g. $PSScriptRoot in PowerShell, __file__ in Python, etc. Note that this is distinct from the current working directory, which is obtainable via Environment.CurrentDirectory and Directory.GetCurrentDirectory().

As a first step to enabling this (i.e. in lieu of a potential API or generated variable or some such in the future), we should update dotnet run to set environment variables when executing file-based apps that contain the path of the entry-point file and the path of the directory the entry-point file is in, e.g.:

  • DOTNET_EXECUTING_FILE_PATH
  • DOTNET_EXECUTING_FILE_DIRECTORY_PATH

Names up for discussion 😄. We may want to consider naming for C# instead of DOTNET, or perhaps do both, e.g.:

  • CSHARP_EXECUTING_FILE_PATH
  • CSHARP_EXECUTING_FILE_DIRECTORY_PATH

Metadata

Metadata

Assignees

Labels

Area-run-fileItems related to the "dotnet run <file>" effort

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0