Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 23, 2025

Currently, when a user runs dotnet <app_path> and the host determines that <app_path> is not a runnable app, it's treated as a CLI command and routed to the SDK, which shows a generic error message.

This PR improves the user experience by detecting when the user passes a path to an existing non-dll/exe file and showing a specific error message instead of routing to the SDK.

cc @dotnet/appmodel @AaronRobinsonMSFT

Changes Made

Core Logic Enhancement:

  • Enhanced argument parsing in command_line.cpp to detect the specific scenario:
    • File is not managed (.dll/.exe)
    • Path contains directory separator
    • File exists
    • Not in exec mode
  • Added specific error message for the above

Behavior Change:

Before:

$ dotnet /path/to/config.json
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  You misspelled a built-in dotnet command.
  You intended to execute a .NET program, but dotnet-/path/to/config.json does not exist.
  You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

After:

$ dotnet /path/to/config.json
The application '/path/to/config.json' does not exist or is not a managed .dll or .exe.

Preserves Existing Behavior:

  • Commands without directory separators (like dotnet build) still route to SDK
  • dotnet exec behavior unchanged
  • All existing error codes and messages unchanged

Test Coverage

Added comprehensive tests covering:

  • Absolute paths with directory separators
  • Relative paths like ./subdir/file.txt
  • Commands without separators still route to SDK
  • Backward compatibility verification

All existing tests pass, confirming no regressions.

Fixes #116939.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits June 23, 2025 23:22
… separators

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI changed the title [WIP] Show specific error message for dotnet <app_path> where <app_path> is a non-dll/exe file that exists Show specific error message for dotnet <app_path> where app_path is a non-dll/exe file that exists Jun 23, 2025
Copilot AI requested a review from elinor-fung June 23, 2025 23:30
…reporting

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested a review from jkotas June 24, 2025 00:14
…error directly in command_line.cpp

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI requested a review from elinor-fung June 24, 2025 02:03
…tions, remove test file

Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
Copilot AI requested a review from elinor-fung June 24, 2025 18:39
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
@AnalogFeelings

This comment was marked as spam.

@am11
Copy link
Member

am11 commented Jun 29, 2025

i wonder how much co2 was released into the air just for this

On the bright side, Copilot gets smarter for future PRs. Plus, CO₂ in its supercritical form has some surprising uses, like powering sCO₂ turbines for electricity. So hey, not all doom and gloom on the hippie’s fry! ✌️

@AnalogFeelings

This comment was marked as off-topic.

@am11
Copy link
Member

am11 commented Jun 29, 2025

the temperatures keep rising and carbon capture is a scam to distract the population from the rampant use of polluting technologies, and no, an LLM cannot get "smarter", its a glorified markov chain with no cognitive processes.

Carbon capture has legitimate applications if used alongside real emissions cuts. And LLMs are far beyond Markov chains, they learn complex patterns across context, not just next-word guessing.

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested a review from jkotas July 1, 2025 20:32
Copilot finished work on behalf of jkotas July 1, 2025 20:32
Co-authored-by: elinor-fung <47805090+elinor-fung@users.noreply.github.com>
if (pal::file_exists(app_candidate))
{
trace::error(_X("The application '%s' is not a managed .dll."), app_candidate.c_str());
return StatusCode::InvalidArgFailure;
Copy link
Member

@jjonescz jjonescz Jul 22, 2025

Choose a reason for hiding this comment

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

We were actually relying on the host to forward these to the CLI, we handle dotnet ./script.cs to run the ./script.cs file-based app.

This PR broke that. Can we revert it? Any better error messages could be implemented in the CLI instead.

Copy link
Member

Choose a reason for hiding this comment

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

Definitely agree here - folks are using this with unix shebangs and that's been a big driver for the file-based app feature set.

Copy link
Member

Choose a reason for hiding this comment

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

/cc @jaredpar

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show specific error message for dotnet <app_path> where <app_path> is a non-dll/exe file that exists

8 participants