Skip to content

Move restore property and item constants to NuGet.Commands #6392

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

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

zivkan
Copy link
Member

@zivkan zivkan commented Apr 12, 2025

Bug

Towards: NuGet/Home#14160

Description

NuGet has string constants for all (or at least the vast majority) of property and items that restore uses to build a PackageSpec. However, those constants were in NuGet.PackageManagement, which is not referenced by msbuild restore, and therefore neither msbuild restore not static graph restore could actually use those constants. Same applies for the newly created PackageSpecFactory added in my previous pull request.

So, this PR moves the classes with the constants to NuGet.Commands, where PackageSpecFactory is, and updates all the string literals to the constants.

This makes the constants available for msbuild and static graph restore as well, but the point of PackageSpecFactory is to be able to delete those implementations, so I didn't update them, to reduce risk of regression and to avoid spending effort code that will be deleted in the future.

Since there's a separate class for item metadata names, I deleted some strings from the project properties class, and had to update references to point to the correct class name.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests no behaviour changes, existing tests should be sufficient.
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc. n/a

@zivkan zivkan requested a review from a team as a code owner April 12, 2025 05:13
@@ -632,9 +632,6 @@ NuGet.ProjectManagement.Preprocessor
NuGet.ProjectManagement.Preprocessor.Preprocessor() -> void
~NuGet.ProjectManagement.Preprocessor.RevertFileAsync(System.Func<System.Threading.Tasks.Task<System.IO.Stream>> streamTaskFactory, string targetPath, System.Collections.Generic.IEnumerable<NuGet.ProjectManagement.InternalZipFileInfo> matchingFiles, NuGet.ProjectManagement.IMSBuildProjectSystem projectSystem, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task
~NuGet.ProjectManagement.Preprocessor.TransformFileAsync(System.Func<System.Threading.Tasks.Task<System.IO.Stream>> streamTaskFactory, string targetPath, NuGet.ProjectManagement.IMSBuildProjectSystem projectSystem, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task
NuGet.ProjectManagement.ProjectBuildProperties
NuGet.ProjectManagement.ProjectItemProperties
NuGet.ProjectManagement.ProjectItems
Copy link
Member Author

Choose a reason for hiding this comment

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

@nkolev92 (or indeed anyone else), do you think we should add type forwarding for these classes?

NuGet.PackageManagement is just such an unlikely package for anyone interacting with NuGet to use, so it seems incredibly unlikely that anyone actually depends on these APIs. Plus, since they're const string, I'm not even use if there's a runtime dependency on the type, or if the compiler copies the const string into the assembly being compiled.

Copy link
Member

@nkolev92 nkolev92 Apr 14, 2025

Choose a reason for hiding this comment

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

I'd say tooling disclaimer applies, mark the issue, make sure it's in the release notes and it's all good.

NuGet.Commands.Restore.Utility.PackageSpecFactory
NuGet.ProjectManagement.ProjectItemProperties
Copy link
Member Author

Choose a reason for hiding this comment

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

As long as the two VS project system implementations use these types, they still need to be public APIs.

If we're willing to break public APIs, then in the future when we delete the old PackageSpec building methods and only have PackageSpecFactory left, then we could consider making these internal. But at the same time, the tech debt of public const strings that can't be changed for breaking changes reasons is very low.

Copy link
Member

Choose a reason for hiding this comment

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

We've always had trouble because these types were not in the correct assembly in the first place, so I'd say this is a great long term thing.

nkolev92
nkolev92 previously approved these changes Apr 14, 2025
@jgonz120 jgonz120 requested review from jeffkl and donnie-msft April 15, 2025 22:19
@jgonz120 jgonz120 marked this pull request as draft April 15, 2025 22:20
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Apr 23, 2025
@zivkan zivkan force-pushed the dev-zivkan-move-item-property-constants branch from 929a656 to afffd03 Compare April 25, 2025 23:54
@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Apr 25, 2025
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label May 3, 2025
Copy link
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants