-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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)
src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
Outdated
Show resolved
Hide resolved
src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
Outdated
Show resolved
Hide resolved
@MiYanni @RikkiGibson @chsienki for reviews, thanks |
I believe the most usage would be scripting with shebang syntax. Should we run it with |
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 |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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 |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
Spec: #47020 (rendered markdown)