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 12 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

public int Execute(string[] binaryLoggerArgs, LoggerVerbosity verbosity)
{
var binaryLogger = GetBinaryLogger(binaryLoggerArgs);
var consoleLogger = new ConsoleLogger(verbosity);
Copy link
Member

Choose a reason for hiding this comment

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

nit: should use new MSBuild API from @MichalPavlik to auto-detect the use of the Console Logger vs the Terminal Logger.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you elaborate? I couldn't find such API.


<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<!-- Override targets which don't work with project files that are not present on disk. -->
Copy link
Member

Choose a reason for hiding this comment

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

Ok now this is some deep magic. It looks like all of this is Restore-time stuff, do we need to add some kinds of flags/detections to enable in-memory use cases for real instead of requiring these workarounds?

cc @rainersigwald / @nkolev92

Copy link
Contributor

Choose a reason for hiding this comment

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

It feels strange that an xml string is needed to make an in-memory project, when we are using the msbuild APIs directly for so many other things.

Copy link
Member Author

@jjonescz jjonescz Feb 27, 2025

Choose a reason for hiding this comment

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

It feels strange that an xml string is needed to make an in-memory project, when we are using the msbuild APIs directly for so many other things.

Isn't that same with strings containing C# that you need when using Roslyn APIs? You could create SyntaxTrees manually but no one does that. Similarly, I could create the MSBuild project without the string but seems that would be less readable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I am relatively comfortable with it, especially if it remains as "just a string" and we don't start using a complex interpolated string with XML escaping handling, etc. to make the project.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok now this is some deep magic. It looks like all of this is Restore-time stuff, do we need to add some kinds of flags/detections to enable in-memory use cases for real instead of requiring these workarounds?

Yes, ideally the targets would allow in-memory builds. Should I file an issue for it at https://github.com/NuGet/Home since the targets live there I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

These are in obj folder right? That still exists (I imagine it would be much more difficult to get rid of that), so I don't think this should be a problem.

Copy link
Member

Choose a reason for hiding this comment

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

not quite - the big problem is that a key file in the obj folder is not 'scoped' to a single project - it's called project.assets.json. This name is customizable though, so your in-memory project here should set that property so that we're future-proof for the "multiple apps in one directory" scenario. That property name is ProjectAssetsFile.

You probably want to make sure that they synthetic project name is unique-per-app too to account for MSBuild logic that does things like $(MSBuildProjectName).foo.bar.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand why is the scoping of the file name a problem?

@jjonescz I think it's a good to consider some sort of a design review for #47020.

It involves NuGet gestures, but the NuGet team hasn't really had a chance to look into that yet.
I've tagged the appropriate people, but it's a bit of short notice for everyone to fully wrap their heads around what's going on.

Copy link
Member

Choose a reason for hiding this comment

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

@nkolev92 when I was looking at the ProjectAssetsFile logic in the targets, right next to it I saw other logic that was using the MSBuildProjectName to compute an intermediate file path - to me that implies that we need to be careful to ensure each 'app' has a distinct project name so that intermediates could reasonably be created in the same intermediate directory without clobbering

Copy link
Member Author

Choose a reason for hiding this comment

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

Scoping could be a problem if we allow multiple virtual projects in one folder, but the proposal currently says they would get separate artifacts folders, so that should avoid any problems.

short notice

I think it is expected that the implementation details of this feature might change over time, so there is no rush.


<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<!-- Override targets which don't work with project files that are not present on disk. -->
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels strange that an xml string is needed to make an in-memory project, when we are using the msbuild APIs directly for so many other things.


<!--
Override targets which don't work with project files that are not present on disk.
See https://github.com/NuGet/Home/issues/14148.
Copy link
Contributor

@nkolev92 nkolev92 Feb 27, 2025

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

static graph is not ever going to be a thing with this loose-file usage mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Static graph restore never triggers any of the target being reported as a problem, so I thought it'd just skip the problem.
Why do we have a concern with static graph?

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