Allow launching file-based apps via dnx - #55676
Draft
jjonescz wants to merge 1 commit into
Draft
Conversation
|
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. |
Contributor
There was a problem hiding this comment.
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 runsupport for a hidden--file-modeplus a user-facing--working-directoryoption, and wire both into the managed and NativeAOT run paths. - Update
dnx/dnx.cmdto detect qualified file-based app paths and dispatch them throughdotnet run --file-mode --working-directory ...instead of tool execution. - Add regression tests and documentation for
dnxfile-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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #49495.
Fixes #54830.
Runtime counterpart: dotnet/runtime#132008