-
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)
{ | ||
if (globalProperties.TryGetValue(key, out var existingValues)) | ||
{ | ||
globalProperties[key] = existingValues + ";" + value; |
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.
[nitpick] Concatenating multiple property values with a semicolon might lead to formatting issues if the existing value already ends with one; consider aggregating values in a list and joining them to ensure proper formatting.
globalProperties[key] = existingValues + ";" + value; | |
var valuesList = existingValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); | |
valuesList.Add(value); | |
globalProperties[key] = string.Join(";", valuesList); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
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.
If user is passing empty properties somehow, I think that's on them. Also, this should be equivalent to pre-existing code, just moved.
@@ -205,6 +199,16 @@ private static string GetDotnetPath() | |||
return new Muxer().MuxerPath; | |||
} | |||
|
|||
internal static Dictionary<string, string> GetMSBuildRequiredEnvironmentVariables() | |||
{ | |||
return new() |
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 know this is code that is already there but surprised this is using an ordinal comparison for environment variable names.
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.
Good catch, I guess I'm keeping this since it's a pre-existing behavior, but let me know if you think I should change this.
for (int i = args.Length - 1; i >= 0; i--) | ||
{ | ||
var arg = args[i]; | ||
if (arg.StartsWith("/bl:") || arg.Equals("/bl") |
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.
Use explicit string comparison arguments
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.
Good idea. This code was copied from elsewhere, let me share it.
It looks like dotnet build
is case insensitive (dotnet build -BL
produces a binlog) whereas dotnet run
is case sensitive (-BL
is passed as an argument to the executed app), so I'm not sure if I should fix that inconsistency and use ignore-case comparison here to make dotnet run -BL
produce binlog as well (but that's technically a breaking change)?
@@ -205,6 +199,16 @@ private static string GetDotnetPath() | |||
return new Muxer().MuxerPath; | |||
} | |||
|
|||
internal static Dictionary<string, string> GetMSBuildRequiredEnvironmentVariables() |
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.
This call is now being used in a few places, sometimes to create a new dictionary and sometimes to just iterate this data which is effectively static. Did you consider instead having a definition like this:
internal static ImmutableDictionary<string, string> MSBuildRequiredEnvironmentVariables { get; } = ...
Then in the places where a new dictionary is needed use new (MSBuildRequiredEnvironmentVariables)
and for iteration it can just use the property directly.
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.
The default env vars cannot be static and initialized only once, they can change.
} | ||
} | ||
|
||
public ProjectInstance CreateProjectInstance(ProjectCollection projectCollection) |
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.
Is there a reason this overload is needed? The below one with the optional should work for the call sites I see.
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.
Yes, there is a delegate created from this one here:
projectFactory = command.CreateProjectInstance; |
The one with the optional argument wouldn't work (would need a lambda wrapper which seems less efficient).
Also this one is public whereas the one with the optional arg isn't exposed, it's private.
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable |
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.
Is this needed? The other files seem to implicitly have nullable analysis enabled
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.
They unfortunately don't, only nullable annotations are enabled, but you get no nullable warnings without this.
Which made me realize I could also nullable-enable the RunCommand.cs file since I did a lot of changes in there too.
Spec: #47020 (rendered markdown)