Skip to content

Add --delete-source option and interactive prompt to project convert#52802

Open
Copilot wants to merge 8 commits intorelease/10.0.3xxfrom
copilot/fix-old-cs-file-issue
Open

Add --delete-source option and interactive prompt to project convert#52802
Copilot wants to merge 8 commits intorelease/10.0.3xxfrom
copilot/fix-old-cs-file-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

  • Add --delete-source command-line option to ProjectConvertCommandDefinition
  • Add option description to CommandDefinitionStrings.resx
  • Update ProjectConvertCommand to read the new option
  • Add interactive prompt using Spectre.Console to ask user if they want to delete/move the source file
  • Implement file deletion logic after successful conversion (non-dry-run mode only)
  • Add localized strings for the interactive prompt to CliCommandStrings.resx
  • Write focused tests for the new functionality:
    • Test with --delete-source flag (file should be deleted)
    • Test without flag in non-interactive mode (file should remain - current behavior)
    • Test with --dry-run and --delete-source flags
    • Test with custom output directory and --delete-source
    • Test with default files (only entry point deleted, not other files)
  • Build and run manual tests to verify the changes
  • Address code review feedback:
    • ✅ Changed DeleteSourceFile to local function DeleteFile (like CreateDirectory/CopyFile)
    • ✅ Removed unnecessary comments
    • ✅ Migrated TryAskForOutputDirectory to Spectre.Console for consistency
    • ✅ Added tests with default files to ensure only entry point is deleted
    • ✅ Removed unused InteractiveConsole.Ask method
    • ✅ Improved output directory validation to validate default value in interactive mode
    • ✅ Added _interactive field to avoid repeated _parseResult.GetValue<bool>(CommonOptions.InteractiveOptionName) calls
    • ✅ Simplified DetermineOutputDirectory by inlining the prompt logic
    • ✅ Updated outdated comment about validation
    • ✅ Removed unused Validator delegate from InteractiveConsole
    • ✅ Removed unused usings from InteractiveConsole
  • Run security scan with CodeQL - No issues found

Summary

This implementation adds a --delete-source command-line option and an interactive prompt to dotnet project convert that allows users to choose whether to delete the original source file after conversion.

Key Features:

  1. Backward Compatible: Default behavior (without flags) preserves the source file
  2. Explicit Control: --delete-source flag deletes the source file after successful conversion
  3. Interactive Mode: With --interactive flag (and no --delete-source), users are prompted via Spectre.Console
  4. Dry-Run Support: Works correctly with --dry-run flag to preview actions
  5. Fully Localized: All user-facing strings are localized in resource files
  6. Well Tested: Comprehensive unit tests cover all scenarios including default files
  7. Consistent UX: Both output directory and delete prompts use Spectre.Console
  8. Improved Validation: Interactive mode now validates default output directory and prompts again if it exists
  9. Clean Code: Simplified logic with _interactive field, inlined prompt, and removed unused code
Original prompt

This section details on the original issue you should resolve

<issue_title>Converting file-based app to project-based app does not get rid of old .cs file</issue_title>
<issue_description>### Steps to repro

  1. Open VSC Insiders
  2. Create folder/workspace
  3. Create hello.cs
  4. Add any code and save
  5. Run dotnet project convert hello.cs

Actual

Project gets created but the old file remains

Image

Expectation

That the project be converted aka the old file should just be moved

Note: In chatting with @DamianEdwards he did mention this choice was originally made to prevent data loss since the action is destructive, but I really did not expect the file to remain, especially since this action is called a "conversion", not "copy as project" for example. It really feels like a bug. At a minimum hopefully the command can ask a secondary question after I input the target directory if I want to remove the old file if you want it to remain interactive or command can have args that i can pass to do this automatically

Environment Info

.NET SDK: (10.0.100-rc.2.25468.101)
VS Code Insiders: 1.105.0-insider
C# Dev Kit Extension: V 1.61.12
C# Extension: V 2.92.18</issue_description>

<agent_instructions>Can you add a command-line argument and an interactive prompt to dotnet project convert that will ask what to do with the original file (copy or move it)? If the command-line option is specified, don't display the prompt (I think that's similar to what we do for --output now). Consider also using Spectre for that interactivity since it's now available in the repo (also migrate the "output" prompt to Spectre if not already).</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@DamianEdwards In the original issue to make `dotnet project convert` interactive, #49624, the detail said to include a question about whether to ask the user whether the original files should be deleted or not and support an option to force it to copy or move, but I'm not seeing that question get asked when I try this myself (which matches the report). There was also some discussion about it in the PR https://github.com//pull/49584#pullrequestreview-2983961087

@jjonescz do you recall why we didn't add the question about copy or moving files as part of convert? Did we just want to wait for feedback?

@jjonescz Yes, the option was confusing, so we removed it. See https://github.com//pull/49660#discussion_r2198099055 where you suggested that :) @DamianEdwards Lol awesome, seems folks found the question confusing so we opted to remove it and let the user delete the files for now. If we get repeated feedback that folks want the files deleted we can revisit, or we could consider adding an option like `--delete-source-files` to allow folks to do it in one command easily. @claudiaregio We are running user testing on this this week so I'll hopefully get some feedback on it, another thing worth considering (and this would be a tooling thing but I dont want to lose the thought) is potentially changing focus to the new file in the project once the conversion is complete. @claudiaregio @DamianEdwards @jjonescz is there any update on whether this can/will be implemented? In user testing they were 50/50 split on whether old project should be destroyed or kept so i think having the parameters that gives the choice would be good @jjonescz We can easily add a parameter (or interactive prompt) but there is some complexity about what this should apply to - just the `file.cs` or other included default items too (like `file.run.json`, `resources.resx`, or even `util.cs` once we have multi-file support)?

Perhaps we could start with just the entrypoint file.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 3, 2026 12:10
…command

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
… improve test assertions

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with leftover .cs file during project conversion Add --delete-source option and interactive prompt to project convert Feb 3, 2026
Copilot AI requested a review from jjonescz February 3, 2026 12:25
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Feb 3, 2026
…ts, migrate to Spectre.Console, add tests with default files

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI requested a review from jjonescz February 3, 2026 13:38
…ory validation

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI requested a review from jjonescz February 3, 2026 14:02
…directory prompt

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI requested a review from jjonescz February 3, 2026 14:21
…nsole

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI requested a review from jjonescz February 3, 2026 14:42
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.

3 participants