Skip to content

Allow launching file-based apps via dnx - #55676

Draft
jjonescz wants to merge 1 commit into
dotnet:mainfrom
jjonescz:54830-sprint-dnx
Draft

Allow launching file-based apps via dnx#55676
jjonescz wants to merge 1 commit into
dotnet:mainfrom
jjonescz:54830-sprint-dnx

Conversation

@jjonescz

@jjonescz jjonescz commented Aug 7, 2026

Copy link
Copy Markdown
Member

Part of #49495.
Fixes #54830.
Runtime counterpart: dotnet/runtime#132008

@jjonescz
jjonescz requested a review from Copilot August 7, 2026 14:59
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Aug 7, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the dnx launcher in the .NET SDK to run file-based apps (in addition to tool packages) while preserving expected SDK resolution behavior (notably global.json) and the user’s original working directory when the app executes.

Changes:

  • Add dotnet run support for a hidden --file-mode plus a user-facing --working-directory option, and wire both into the managed and NativeAOT run paths.
  • Update dnx/dnx.cmd to detect qualified file-based app paths and dispatch them through dotnet run --file-mode --working-directory ... instead of tool execution.
  • Add regression tests and documentation for dnx file-based app execution and the new working-directory behavior.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests_General.cs Adds end-to-end tests for dnx file-based app dispatch, argument forwarding, and global.json/cwd behavior; adds a test for dotnet run --working-directory.
test/dotnet.Tests/CommandTests/Run/RunCommandTests.cs Adds unit tests asserting --working-directory overrides launch profile and evaluated/cached run properties.
test/dotnet-aot.Tests/AotRunCommandTests.cs Updates NativeAOT run tests for --working-directory and adds file-mode resolution behavior coverage.
src/Layout/redist/dnx.cmd Implements Windows dnx.cmd detection of qualified file-based app paths and dispatches via dotnet run --file-mode --working-directory.
src/Layout/redist/dnx Implements POSIX dnx detection of qualified file-based app paths and dispatches via dotnet run --file-mode --working-directory.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hant.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.zh-Hans.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.tr.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ru.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pt-BR.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.pl.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ko.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.ja.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.it.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.fr.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.es.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.de.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/xlf/CommandDefinitionStrings.cs.xlf Adds localized entries for dnx and new dotnet run option descriptions.
src/Cli/Microsoft.DotNet.Cli.Definitions/Common/CommonArguments.cs Generalizes package identity argument creation to allow a custom argument name (used by dnx).
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Tool/ToolExecuteCommandDefinition.cs Allows overriding the package identity argument name and defers initialization to constructor.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Run/RunCommandDefinition.cs Adds --file-mode (hidden) and --working-directory options to dotnet run.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Dnx/DnxCommandDefinition.cs Updates dotnet dnx definition/strings to reflect file-or-package input and argument forwarding semantics.
src/Cli/Microsoft.DotNet.Cli.Definitions/CommandDefinitionStrings.resx Adds new resource strings for dnx and dotnet run option descriptions.
src/Cli/dotnet/Commands/Run/RunCommand.cs Plumbs --working-directory and file-mode parsing through managed dotnet run execution.
src/Cli/dotnet/Commands/Run/CommonRunHelpers.cs Adds shared helper for file-mode argument processing and token splitting at --.
src/Cli/dotnet/Commands/Run/Api/RunApiCommand.cs Updates API usage to pass the new workingDirectory parameter when constructing RunCommand.
src/Cli/dotnet/Commands/Run/AotRunCommand.cs Adds NativeAOT support for file-mode + working-directory override and aligns eligibility checks.
documentation/general/dotnet-run-file.md Documents dnx support for file-based apps and describes SDK resolution/working-directory behavior.

Comment on lines +815 to +820
string? workingDirectory = parseResult.GetValue(definition.WorkingDirectoryOption);

if (workingDirectory is not null)
{
workingDirectory = Path.GetFullPath(workingDirectory);
}
Comment on lines +29 to +32
if (applicationArguments is not [{ } filePath, ..])
{
throw new GracefulException(CliCommandStrings.InvalidFilePath, string.Empty);
}
Comment on lines +132 to +138
```ps1
dnx ./some/path.cs arg0 arg1
```

This is equivalent to `dotnet run --file ./some/path.cs -- arg0 arg1`.
All arguments after the target path are passed to the app verbatim, including a literal `--`
and arguments that have the same names as `dnx` tool options.
Comment on lines +140 to +144
For file-based apps, `dnx` starts the `dotnet` host with the target directory as its working directory so SDK resolution,
including the search for `global.json`, starts from the target directory rather than the directory from which `dnx` was invoked.
After the SDK CLI has started, `dnx` restores the original working directory before building and running the app.
Consequently, implicit build files such as `Directory.Build.props` are still discovered relative to the file-based app,
while the running app observes the directory from which the user invoked `dnx` as its current working directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running file-based apps from $PATH can trip up on global.json in current directory

2 participants