Skip to content

Implement #:package manipulation for file-based apps #49635

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Jul 2, 2025

Part of #49200. This PR implements dotnet package add and dotnet package remove.

When more logic is shared with NuGet, more package-related commands can be implemented and some of the logic here simplified. See NuGet/Home#14390.

I've modeled the commands around their project-based counterparts. package remove is relatively simple - corresponding #:package directives are removed from the C# file, Directory.Packages.props is not considered at all. package add needs to update Directory.Packages.props if Central Package Management is enabled. It also needs to perform restore. If no version is specified by the user on the command-line, it needs to determine the latest version and put that into the package reference directive.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Jul 2, 2025
@jjonescz jjonescz marked this pull request as ready for review July 2, 2025 17:02
@jjonescz jjonescz requested review from Copilot and a team July 2, 2025 17:02
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 PR extends the dotnet package commands to support file-based C# apps by introducing a --file option, updating parsing/completion, and adding source‐editor logic to manipulate #:package directives.

  • Introduces --file alongside --project in parsers and completion scripts
  • Implements add/remove of #:package directives in FileBasedAppSourceEditor and wiring in PackageAddCommand / PackageRemoveCommand
  • Adds extensive unit tests and updates documentation for the new file-based scenarios

Reviewed Changes

Copilot reviewed 57 out of 57 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Cli/dotnet/Commands/Package/PackageCommandParser.cs Adds FileOption and path‐processing logic for file-based apps
src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs Implements file‐based add logic, including CPM and restore support
src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs Implements file‐based remove logic and reports removed directives
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Refactors diagnostics handling and directive loading for files
src/Cli/dotnet/Commands/Run/FileBasedAppSourceEditor.cs New editor for inserting/removing #:package directives
src/Cli/dotnet/Commands/Run/RunCommand.cs Updates error message constant for invalid option combinations
Comments suppressed due to low confidence (1)

src/Cli/dotnet/Commands/Run/FileBasedAppSourceEditor.cs:105

  • Typo in variable name addAfer—it should be spelled addAfter to match the intended meaning.
        CSharpDirective? addAfer = null;

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.

1 participant