Skip to content

Improve support of nuget commands with file-based apps#53535

Open
jjonescz wants to merge 16 commits intodotnet:release/10.0.3xxfrom
jjonescz:49200-nuget-commands
Open

Improve support of nuget commands with file-based apps#53535
jjonescz wants to merge 16 commits intodotnet:release/10.0.3xxfrom
jjonescz:49200-nuget-commands

Conversation

@jjonescz
Copy link
Copy Markdown
Member

Resolves #49200.
Needs NuGet/NuGet.Client#7169.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Mar 19, 2026
@jjonescz jjonescz marked this pull request as ready for review March 26, 2026 13:56
@jjonescz jjonescz requested a review from a team as a code owner March 26, 2026 13:56
@jjonescz jjonescz requested review from a team and Copilot March 26, 2026 13:56
Copy link
Copy Markdown
Contributor

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

Extends file-based app support to NuGet-related CLI flows by integrating a virtual project builder into NuGet XPlat execution, so dotnet package * and dotnet nuget why can operate on *.cs entrypoints and reflect package changes back into #:package directives.

Changes:

  • Add an IVirtualProjectBuilder implementation for file-based apps and a reflector that syncs NuGet-edited PackageReference items back into #:package directives.
  • Route dotnet package add/remove/list and dotnet nuget why through updated NuGet XPlat entrypoints, including in-proc execution when needed.
  • Update tests and remove the obsolete DirectivesRemoved localized resource entry.

Reviewed changes

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

Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs Adds coverage for creating a NuGet-compatible virtual project root element from a file-based app.
test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs Updates call-site for new VirtualProjectBuilder.CreateProjectInstance out parameter.
test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs Updates expectations to NuGet-driven output for file-based package removal.
test/dotnet.Tests/CommandTests/Package/List/GivenDotnetListPackage.cs Adds test for listing packages for a file-based app via dotnet list … package.
test/dotnet.Tests/CommandTests/NuGet/GivenANuGetCommand.cs Adds file-based app coverage for nuget why and package update.
src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs Extends CreateProjectInstance to also return a ProjectRootElement for reuse by NuGet.
src/Common/EnvironmentVariableNames.cs Adds DOTNET_HOST_PATH constant.
src/Cli/dotnet/Parser.cs Passes the virtual project builder into NuGet XPlat command registration.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf Removes DirectivesRemoved translation entry.
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Adds NoConsoleLogger and tweaks restore/build target handling for virtual projects.
src/Cli/dotnet/Commands/Run/Api/RunApiCommand.cs Updates call-site for new CreateProjectInstance out parameter ordering.
src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs Updates call-site for new CreateProjectInstance out parameter.
src/Cli/dotnet/Commands/Package/VirtualProjectPackageReflector.cs New: reflects NuGet PackageReference changes back into #:package directives.
src/Cli/dotnet/Commands/Package/Remove/PackageRemoveCommand.cs Routes file-based removal through NuGet virtual project path instead of manual directive editing.
src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs Enables restore+list for file-based apps by using virtual project restore and NuGet runner selection.
src/Cli/dotnet/Commands/Package/Add/PackageAddCommand.cs Routes file-based add through NuGet runner and uses virtual project build to generate restore graph when needed.
src/Cli/dotnet/Commands/NuGet/NuGetVirtualProjectBuilder.cs New: implements NuGet XPlat IVirtualProjectBuilder for file-based apps.
src/Cli/dotnet/Commands/NuGet/NuGetCommand.cs Adds in-proc NuGet runner selection for file-based scenarios and ensures DOTNET_HOST_PATH is set.
src/Cli/dotnet/Commands/CliCommandStrings.resx Removes DirectivesRemoved resource.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Package/PackageListCommandDefinition.cs Adds --file/--project options to dotnet package list and aligns path parsing API.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Hidden/List/ListReferenceCommandDefinition.cs Updates hidden dotnet list to accept file paths via unified argument.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Hidden/List/ListPackageCommandDefinition.cs Updates hidden dotnet list … package to accept file paths via unified argument.
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Hidden/List/ListCommandDefinition.cs Renames argument to “solution/project/file” to reflect new supported inputs.

Copy link
Copy Markdown
Contributor

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

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

Looks fine to me, nothing stands out.

Please get an SDK reviewer here, don't just rely on my approval.

@jjonescz jjonescz force-pushed the 49200-nuget-commands branch 2 times, most recently from daf7b83 to 053c44f Compare March 28, 2026 13:32
@jjonescz jjonescz force-pushed the 49200-nuget-commands branch from 053c44f to 5c20baa Compare March 28, 2026 13:39
@jjonescz
Copy link
Copy Markdown
Member Author

@333fred @RikkiGibson @MiYanni for reviews, thanks

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