Skip to content

Warn about common run-file pitfalls#53833

Merged
jjonescz merged 4 commits intodotnet:release/10.0.3xxfrom
jjonescz:sprint-project-warn
Apr 17, 2026
Merged

Warn about common run-file pitfalls#53833
jjonescz merged 4 commits intodotnet:release/10.0.3xxfrom
jjonescz:sprint-project-warn

Conversation

@jjonescz
Copy link
Copy Markdown
Member

See for example #52714 (comment).

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds targeted warnings to help users avoid a common pitfall where dotnet run file.cs (or dotnet build file.cs with extra args) is interpreted as a project/MSBuild invocation instead of a file-based program execution.

Changes:

  • Add warnings for suspicious “file-like” arguments when dotnet run falls back to running a project, and when other commands fall back to MSBuild.
  • Add new localized strings for these warnings.
  • Expand RunFileTests coverage for warning/no-warning scenarios (including --project / --file / -- behaviors and extra-arg fallback cases).

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Adds/updates tests validating the new warning behavior and stderr expectations.
src/Cli/dotnet/Commands/Run/RunCommand.cs Emits warnings when an argument looks like a file-based entry point but execution is project-based.
src/Cli/dotnet/Commands/CommandFactory.cs Emits warnings when arguments look file-based but command execution falls back to MSBuild.
src/Cli/dotnet/Commands/CliCommandStrings.resx Adds the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf Adds localized entries for the new warning strings.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf Adds localized entries for the new warning strings.

Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf Outdated
Comment thread src/Cli/dotnet/Commands/CliCommandStrings.resx Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf Outdated
Comment thread src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf Outdated
@jjonescz jjonescz marked this pull request as ready for review April 14, 2026 09:49
@jjonescz jjonescz requested a review from a team April 14, 2026 09:49
Copy link
Copy Markdown
Member

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

LGTM. CI failures look unrelated.

@jjonescz
Copy link
Copy Markdown
Member Author

@333fred @MiYanni for reviews, thanks

<value>Couldn't find a project to run. Ensure a project exists in {0}, or pass the path to the project using {1}.</value>
</data>
<data name="RunCommandWarningFileArgumentPassedToProject" xml:space="preserve">
<value>Warning: '{0}' appears to be a file-based program but was passed as an argument to the project '{1}'. To run it as a file-based program, use 'dotnet run --file {0}'. To pass it as an application argument, use 'dotnet run -- {0}' to suppress this warning.</value>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should use file-based application as that's its official name

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks

@jjonescz jjonescz merged commit ccdab30 into dotnet:release/10.0.3xx Apr 17, 2026
28 checks passed
@jjonescz jjonescz deleted the sprint-project-warn branch April 17, 2026 11:17
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.

6 participants