Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for 'dotnet run file.cs' #46915

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Feb 18, 2025

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Feb 18, 2025
@jjonescz jjonescz marked this pull request as ready for review February 19, 2025 12:15
@Copilot Copilot bot review requested due to automatic review settings February 19, 2025 12:15
Copy link
Contributor

@Copilot 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.

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

src/Cli/dotnet/commands/dotnet-run/RunCommand.cs:609

  • [nitpick] The method 'DiscoverProjectFilePath' now returns both a project file path and an entry point file via an out parameter; consider renaming it (for example, to 'DiscoverProjectAndEntryPointPaths') to better reflect its dual purpose.
private static string? DiscoverProjectFilePath(string? projectFileOrDirectoryPath, ref string[] args, out string? entryPointFilePath)

src/Cli/dotnet/commands/dotnet-run/RunCommand.cs:250

  • [nitpick] Consider renaming the 'projectFactory' out parameter to 'projectInstanceFactory' for improved clarity since it is intended to supply a ProjectInstance.
private void EnsureProjectIsBuilt(out Func<ProjectCollection, ProjectInstance>? projectFactory)

@RikkiGibson RikkiGibson self-assigned this Feb 19, 2025
@jjonescz
Copy link
Member Author

@MiYanni @RikkiGibson @chsienki for reviews, thanks

@baronfel baronfel added Area-run-file Items related to the "dotnet run <file>" effort and removed untriaged Request triage from a team member Area-CLI labels Feb 27, 2025
@hez2010
Copy link

hez2010 commented Mar 4, 2025

I believe the most usage would be scripting with shebang syntax. Should we run it with Release config by default to avoid unnecessary by-default slow down?

@jjonescz
Copy link
Member Author

jjonescz commented Mar 4, 2025

I believe the most usage would be scripting with shebang syntax. Should we run it with Release config by default to avoid unnecessary by-default slow down?

I would rather not change any defaults to avoid confusion. However, if you are using shebang, presumably you will specify the Release config there:

#!/usr/bin/dotnet run -c Release

Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

I heard offline that the new plan is to have it just build/execute one file instead of globbing everything in the current directory and subdirectories. That's my last serious concern right now, so I'm happy signing off preemptively 🙂 Thanks for all your work on this! I think it's a fantastic improvement in the new user experience


if (!HasTopLevelStatements(arg))
{
throw new GracefulException(LocalizableStrings.NoTopLevelStatements, arg);
Copy link
Member Author

@jjonescz jjonescz Mar 11, 2025

Choose a reason for hiding this comment

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

In theory, we could remove this restriction now and let the compiler report errors if an entrypoint is missing in the compilation (consisting of the sole input file). However, if we decide to add the support for multiple files back, we will likely want this restriction again. So, I think it's better to keep the restriction (to avoid a breaking change later) and relax it in the future if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

I'd personally be mildly in favor of removing it mostly because I think top level statements were a bad idea in the first place. (I'm not sure how to do this, but a different check that verifies that there is an entrypoint in this file would be perfect in my view.) On the other hand, I do think your logic is sound, so I think it's ok to keep this.

@jjonescz
Copy link
Member Author

@MiYanni @Forgind @chsienki @RikkiGibson. I've updated this PR to limit to single file instead of globbing. Please take a look if you want, I'd like to merge if there are no objections and follow up with other PRs (like grow up command and #package directive). Thanks.

Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

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

No objections—thanks for your work on this!


if (!HasTopLevelStatements(arg))
{
throw new GracefulException(LocalizableStrings.NoTopLevelStatements, arg);
Copy link
Member

Choose a reason for hiding this comment

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

I'd personally be mildly in favor of removing it mostly because I think top level statements were a bad idea in the first place. (I'm not sure how to do this, but a different check that verifies that there is an entrypoint in this file would be perfect in my view.) On the other hand, I do think your logic is sound, so I think it's ok to keep this.

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.