Warn about common run-file pitfalls#53833
Merged
jjonescz merged 4 commits intodotnet:release/10.0.3xxfrom Apr 17, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 runfalls back to running a project, and when other commands fall back to MSBuild. - Add new localized strings for these warnings.
- Expand
RunFileTestscoverage 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. |
RikkiGibson
approved these changes
Apr 14, 2026
Member
RikkiGibson
left a comment
There was a problem hiding this comment.
LGTM. CI failures look unrelated.
Member
Author
333fred
approved these changes
Apr 16, 2026
chsienki
reviewed
Apr 16, 2026
| <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> |
Member
There was a problem hiding this comment.
We should use file-based application as that's its official name
MiYanni
approved these changes
Apr 16, 2026
This was referenced Apr 17, 2026
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.
See for example #52714 (comment).