Skip to content

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

Merged
jjonescz merged 16 commits intorelease/10.0.3xxfrom
copilot/fix-old-cs-file-issue
Mar 6, 2026
Merged

Add --delete-source option and interactive prompt to project convert#52802
jjonescz merged 16 commits intorelease/10.0.3xxfrom
copilot/fix-old-cs-file-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

dotnet project convert copies source files to the new project directory but leaves the original files. Users expect "convert" to move the files, not duplicate them.

Changes

  • New --delete-source flag: Explicitly deletes ALL source files after successful conversion (entry point + all included items from #:include directives, default globbing, etc.)
  • Interactive prompt: When --interactive is enabled without --delete-source, prompts user via Spectre.Console to choose whether to irreversibly delete all source files
  • Backward compatible: Default behavior unchanged (all source files preserved)
  • Dry-run support: Shows deletion preview with --dry-run --delete-source
  • Scripting support: --interactive=false explicitly disables all prompts for reliable scripting
  • Migrated output directory prompt to Spectre.Console: Both prompts now use Spectre.Console for consistent UX

Behavior

# Default - all source files preserved (existing behavior)
dotnet project convert hello.cs

# Delete all source files (entry point + all included items)
dotnet project convert hello.cs --delete-source
# Output: Deleted source file: /path/to/hello.cs
#         Deleted source file: /path/to/Util.cs
#         Deleted source file: /path/to/appsettings.json
#         (deletes ALL files discovered by conversion, regardless of type)

# Interactive mode prompts user for both output directory and source deletion
dotnet project convert hello.cs --interactive
# Prompts for output directory, then: "Delete all source files after conversion?"
#   > Yes - delete all source files
#     No - keep all source files

# Scripting - explicitly disable prompts
dotnet project convert hello.cs --interactive=false
# No prompts, uses defaults, preserves all source files

What Gets Deleted

When --delete-source is used, ALL of the following files are irreversibly deleted:

  • ✅ Entry point file (e.g., hello.cs)
  • ✅ Files from #:include directives (e.g., Util.cs, Helper.cs)
  • ✅ Transitively included files (directives in included files)
  • ✅ Default items from globbing (e.g., appsettings.json, other .cs files)
  • ALL items discovered by FindIncludedItems() regardless of type (Compile, None, EmbeddedResource, etc.)

This provides complete cleanup - only the new project directory remains with all files copied into it.

Implementation Notes

  • Deletes ALL items discovered during project conversion (entry point + all included items)
  • Interactive prompts use Spectre.Console with localized strings clearly warning about irreversible deletion of "all source files"
  • Falls back gracefully if Spectre.Console fails (e.g., unsupported terminal)
  • All user-facing strings added to resource files for localization with clarifying comments
  • The --interactive option now accepts boolean arguments (--interactive=true/false) for explicit control in scripts
  • Tests cover all scenarios: explicit flag, non-interactive default, dry-run, custom output, default files, #:include directives, and transitive includes
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
…ective interaction

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI requested a review from jjonescz March 2, 2026 19:24
…ude directives

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copy link
Member

@jjonescz jjonescz left a comment

Choose a reason for hiding this comment

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

Co-authored-by: jjonescz <3669664+jjonescz@users.noreply.github.com>
Copilot AI requested a review from jjonescz March 3, 2026 17:59
@jjonescz jjonescz requested a review from 333fred March 3, 2026 22:57
@jjonescz jjonescz merged commit a0f0828 into release/10.0.3xx Mar 6, 2026
28 checks passed
@jjonescz jjonescz deleted the copilot/fix-old-cs-file-issue branch March 6, 2026 00:50
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