Skip to content

Add command 'dotnet project convert' #47500

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

Merged
merged 9 commits into from
Mar 18, 2025
Merged

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Mar 12, 2025

I have also removed the check for top-level statements because I've realized that

  • it's not correct in all cases, e.g., when there are some <DefineConstants> in an implicit build file or on the command line, they would not be considered when using Roslyn API to detect top-level statements but they would be recognized during the build itself, potentially leading to inconsistencies (I've added tests for that),
  • even if we allow multi-file support and want to error on dotnet run util.cs, we can do that check in Roslyn instead, avoiding the <DefineConstants> problem and reusing its logic for detecting entrypoints, hence also recognizing all forms of Main methods, not just top-level statements.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Mar 12, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Mar 12, 2025
@jjonescz jjonescz marked this pull request as ready for review March 12, 2025 13:24
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.

Pull Request Overview

This pull request adds a new "dotnet project add" command that creates a project folder and generates a non-virtual project file based on an entry point file. It introduces:

  • A new command implementation (ProjectAddCommand) and parser (ProjectAddCommandParser) to handle the add operation.
  • Updates to the virtual project building logic and project command integration.
  • Minor type qualification updates for consistency in related modules.

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Cli/dotnet/commands/dotnet-project/add/ProjectAddCommand.cs Implements the new add command; creates a project folder and moves/updates files accordingly.
src/Cli/dotnet/commands/dotnet-project/add/ProjectAddCommandParser.cs Adds the parser for the new command.
src/Cli/dotnet/commands/dotnet-project/ProjectCommandParser.cs Integrates the new subcommand into the project command.
src/Cli/dotnet/commands/VirtualProjectBuildingCommand.cs Adds common project properties and updates project file generation.
src/Cli/dotnet/Parser.cs Registers the new project command.
src/Cli/dotnet/Extensions/ProjectExtensions.cs Updates parameter types for consistency.
src/Cli/dotnet/MsbuildProject.cs Updates type qualification for evaluated projects.
Comments suppressed due to low confidence (1)

src/Cli/dotnet/commands/dotnet-project/add/ProjectAddCommand.cs:23

  • [nitpick] The variable name 'file' is ambiguous and may benefit from a more descriptive name such as 'fullFilePath' to clarify its purpose.
string file = Path.GetFullPath(_file);

Copy link
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

LGTM.

I did have a question about the verbiage of dotnet project add given that we have dotnet add <projectfile> as an existing command, but thats for the spec, and this PR matches what's currently in the spec.

@jjonescz
Copy link
Member Author

given that we have dotnet add <projectfile> as an existing command

You mean dotnet add package and dotnet add reference? Yeah, Chet said they are moving away from verb-first to noun-first. And so there are actually now also dotnet package add and dotnet reference add.

@baronfel
Copy link
Member

Correct - we prefer noun-first as much as possible starting in 10.0.

@baronfel
Copy link
Member

We'll probably talk about this in design but I really don't like the dotnet project add verb/command chosen here. It's way to general IMO. We'll need to bikeshed about a proper name before .NET 10 RC1.

@RikkiGibson
Copy link
Member

RikkiGibson commented Mar 13, 2025

It feels like a verb like convert/migrate/move would be appropriate here. But not suggesting to rename the command in this PR.

Co-authored-by: Rikki Gibson <[email protected]>
@jjonescz
Copy link
Member Author

@MiYanni for a review, thanks

@Forgind
Copy link
Member

Forgind commented Mar 14, 2025

We'll probably talk about this in design but I really don't like the dotnet project add verb/command chosen here. It's way to general IMO. We'll need to bikeshed about a proper name before .NET 10 RC1.

I'd like to come up with a good answer for this before taking a real look at this. Project feels wrong to me. I don't have a good answer to replace it yet; my best is library. dotnet library add? I don't like that, but that's all I've come up with

@DamianEdwards
Copy link
Member

Ideas for other command names, with assumption that each accepts file name as an argument:

  • dotnet project init
  • dotnet project eject
  • dotnet project create
  • dotnet project convert
  • dotnet project up
  • dotnet project growup
  • dotnet project upgrade
  • dotnet new project

What ChatGPT settled on:

Final Recommendation
If the goal is transitioning from a script to a full project, I’d recommend dotnet project convert or dotnet project upgrade for the clearest intent.

If you want to align with .NET CLI conventions more broadly, dotnet project init or dotnet project create could work, but they might be slightly misleading in terms of upgrading an existing entry-point file.

https://chatgpt.com/share/67d4cad7-c7a4-8012-85f2-a0eb5286553e

@jjonescz
Copy link
Member Author

jjonescz commented Mar 17, 2025

I have a PR for #: directive handling almost ready, but it's based on this one (most of the tests of the directive processing will take a C# text with the directives as input and verify the .csproj after grow up matches expectations). (EDIT: I guess we don't need the CLI command for that, an internal API for the tests is enough; but still will need some effort to rebase this PR out of that one.) Do we want to block that until we settle on the CLI command name here, or can we go with dotnet project add for now? I can also retarget to a feature branch instead of main if that helps.

@baronfel
Copy link
Member

I like 'dotnet project convert' quite a lot (lots of space for like a --from-file, or --from-Xyz if we need it). I'm also looking at a far future with a 'dotnet project upgrade' sibling command, and that feels pretty nice.

@jjonescz
Copy link
Member Author

jjonescz commented Mar 17, 2025

I like 'dotnet project convert' quite a lot (lots of space for like a --from-file, or --from-Xyz if we need it). I'm also looking at a far future with a 'dotnet project upgrade' sibling command, and that feels pretty nice.

Okay, I like that as well, and I can change to that easily. Thanks.

@jjonescz
Copy link
Member Author

@MiYanni or @Forgind for a review, thanks

@baronfel baronfel changed the title Add command 'dotnet project add' Add command 'dotnet project convert' Mar 17, 2025
Copy link
Member

Choose a reason for hiding this comment

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

@baronfel So, is it intended that every CLI surface change requires these 3 completion tests to have changes? It looks like it requires at least some Bash, PowerShell, and ZSH knowledge to do this, which is a pretty high bar.

Copy link
Member

Choose a reason for hiding this comment

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

yes, it's intended. the CLI interface is a public interface, and we need to be careful about it the same way as we would a REST response or any other API.

these tests are one kind of gate in that regard.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it requires at least some Bash, PowerShell, and ZSH knowledge to do this, which is a pretty high bar.

Note that these are automatically generated snapshots.

@@ -300,7 +297,7 @@ public void ClassLibrary_EntryPointFileExists()
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should().Fail()
.And.HaveStdErrContaining(s_noTopLevelStatements);
.And.HaveStdOutContaining("error CS5001:"); // Program does not contain a static 'Main' method suitable for an entry point
Copy link
Member

Choose a reason for hiding this comment

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

Is the word "error" localized? Meaning, would this word change if it was run in a different language environment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it should be. Note that this is the output of the Roslyn compiler. Not sure why you are asking? It doesn't look like sdk tests run in different locales and there are many tests that verify localizable strings against their English variant. But for example, in Roslyn tests, we don't do that as we run the tests also on non-English locales intentionally. If you intend to do that as well in sdk in the future, let me know, I will try to rewrite my tests so they are locale-insensitive.

Copy link
Member

Choose a reason for hiding this comment

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

Some people run SDK tests locally. They would get localized outputs for this sort of thing, so this test wouldn't work for them as-is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, I can follow up with a PR that ensures RunFileTests and DotnetProjectConvertTests can run on localized machines.

But I want to reiterate that this is a pre-existing problem for many other tests, e.g., https://github.com/search?q=repo%3Adotnet%2Fsdk%20HaveStdErrContaining&type=code

@jjonescz jjonescz merged commit b2845af into dotnet:main Mar 18, 2025
39 checks passed
@jjonescz jjonescz deleted the sprint-grow branch March 18, 2025 17:22
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 untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants