-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve support of nuget commands with file-based apps #53535
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
jjonescz
merged 21 commits into
dotnet:release/10.0.3xx
from
jjonescz:49200-nuget-commands
Apr 10, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4636072
Implement IVirtualProjectBuilder for NuGet
jjonescz 6f441ad
Add support for `dotnet list file.cs package`
jjonescz 0a3ae61
Mark the type as non-trimmable
jjonescz b17ab5e
Handle `package add`
jjonescz d27f21e
Handle `package remove`
jjonescz c075657
Handle `package update`
jjonescz a9b5e95
Handle `package list`
jjonescz 02d6243
Move update test next to the project-based one
jjonescz 461de77
Handle `nuget why`
jjonescz 2dcd1e7
Test the `--file` option
jjonescz 1f019cd
Set DOTNET_HOST_PATH when invoking NuGet
jjonescz 8d28cc1
Merge branch 'release/10.0.3xx' into 49200-nuget-commands
jjonescz aba5332
Improve code
jjonescz fff4853
Merge branch 'release/10.0.3xx' into 49200-nuget-commands
jjonescz 5c20baa
Fixup tests
jjonescz ca1bc34
Fixup more tests
jjonescz 8dee4f7
Improve code
jjonescz 3fb5aed
Fixup wrong condition
jjonescz 32426a0
Fixup formatting of a test output
jjonescz 8c0b968
Flatten `if`s
jjonescz eab01e0
Use named arguments for `out _`
jjonescz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Cli/dotnet/Commands/NuGet/NuGetVirtualProjectBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Build.Construction; | ||
| using Microsoft.Build.Evaluation; | ||
| using Microsoft.DotNet.Cli.Commands.Package; | ||
| using Microsoft.DotNet.Cli.Commands.Run; | ||
| using Microsoft.DotNet.FileBasedPrograms; | ||
| using Microsoft.DotNet.ProjectTools; | ||
| using NuGet.CommandLine.XPlat; | ||
|
|
||
| namespace Microsoft.DotNet.Cli.Commands.NuGet; | ||
|
|
||
| internal sealed class NuGetVirtualProjectBuilder : IVirtualProjectBuilder | ||
| { | ||
| public static NuGetVirtualProjectBuilder Instance => field ??= new(); | ||
|
|
||
| private NuGetVirtualProjectBuilder() { } | ||
|
|
||
| public bool IsValidEntryPointPath(string entryPointFilePath) => VirtualProjectBuilder.IsValidEntryPointPath(entryPointFilePath); | ||
|
|
||
| public string GetVirtualProjectPath(string entryPointFilePath) => VirtualProjectBuilder.GetVirtualProjectPath(entryPointFilePath); | ||
|
|
||
| public ProjectRootElement CreateProjectRootElement(string entryPointFilePath, ProjectCollection projectCollection) | ||
| { | ||
| if (!Path.IsPathFullyQualified(entryPointFilePath)) | ||
| { | ||
| throw new ArgumentException($"'{entryPointFilePath}' is not a fully qualified path.", paramName: nameof(entryPointFilePath)); | ||
| } | ||
|
|
||
| var builder = new VirtualProjectBuilder(entryPointFilePath, VirtualProjectBuildingCommand.TargetFramework); | ||
|
|
||
| builder.CreateProjectInstance( | ||
| projectCollection, | ||
| ErrorReporters.IgnoringReporter, | ||
| project: out _, | ||
| out var projectRootElement, | ||
| evaluatedDirectives: out _); | ||
|
|
||
| return projectRootElement; | ||
| } | ||
|
|
||
| public void SaveProject(string entryPointFilePath, ProjectRootElement projectRootElement) | ||
| { | ||
| VirtualProjectPackageReflector.ReflectChangesToDirectives(projectRootElement, entryPointFilePath); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.