-
Notifications
You must be signed in to change notification settings - Fork 693
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
Disable floating versions in project level for CPM #5011
Conversation
After creating the PR, I realized that I should add tests for |
src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageDetailControlModel.cs
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs
Outdated
Show resolved
Hide resolved
I think in |
@kartheekp-ms I'm not seeing in docs nor in manual testing that
..but an explicit version does work...
|
Thank you for taking the time to check if |
Thanks @donnie-msft for checking the behavior, you're right floating versions are not supported in CPM, this PR disables floating versions in the CPM and talking with Jeff we thought about disabling the button from the Project Level too to avoid confusion in the users. But as @kartheekp-ms says, adding a package using dotnet inside a project works and the behavior should be the same. I think we should not disable adding/updating a package in the Project Level |
We can disable floating versions controls in PM UI when CPM is enabled, and that's the point of the linked issue and this PR, right? This PR is a bug fix, and I'm not seeing how a new feature request is blocking it. Please schedule time with me if I'm still not on the same page. |
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. |
Updated the PR, this no longer disabled the Update/Install button in project level. |
src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageDetailControlModel.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageManagerControl.xaml.cs
Outdated
Show resolved
Hide resolved
@@ -567,6 +569,22 @@ private async Task PackageSourcesChangedAsync(IReadOnlyCollection<PackageSourceC | |||
} | |||
} | |||
|
|||
private async Task IsCentralPackageManagementEnabledAsync(CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly then CPM is enabled for all projects or not, so just checking for 1st project would be suffice.
private async Task IsCentralPackageManagementEnabledAsync(CancellationToken cancellationToken) | |
private async Task IsCentralPackageManagementEnabledAsync(CancellationToken cancellationToken) | |
{ | |
if (!Model.IsSolution) | |
{ | |
await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate | |
{ | |
// Go off the UI thread to perform non-UI operations | |
await TaskScheduler.Default; | |
if (Model.Context.Projects.Any()) | |
{ | |
_detailModel.IsCentralPackageManagementEnabled = await Model.Context.Projects.First().IsCentralPackageManagementEnabledAsync(Model.Context.ServiceBroker, cancellationToken); | |
} | |
}); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can skip the Any()
and just use the First()
as I suggested here: #5011 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that case we're making assumption, there would be at least 1 project, Any
is for safeguarding any unexpected null exception error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go with First()
because as donnie said, we use it on other places and we're not afraid to make that assertion. I would normally go with Any()
to avoid errors but the PM UI cannot be opened without a project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still didn't implement First()
. For you no need to loop. You can use above code without Any()
check too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I forgot to push new changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly then CPM is enabled for all projects or not
That's not correct. CPM (and PackageReference) is implemented via MSBuild, and MSBuild is strictly per-project. Trying to enforce anything to be "all of solution or none" in MSBuild is effectively impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinrrm
Have you looked into above scenario? Do we consider it CPM enabled if some projects are CPM enabled but not all? Maybe check with @jeffkl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code will only run in the project PM UI, so if the user has disabled CPM for that project, it can install any version. I understand that disable CPM in just a project is not a desired behavior for this feature but since its msbuild it difficult to restrain users from doing it. @jeffkl can you confirm this?
src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Services/NuGetProjectManagerService.cs
Show resolved
Hide resolved
f601fe7
to
5aacf80
Compare
@donnie-msft @erdembayar Can a get a review again? Thanks! |
src/NuGet.Clients/NuGet.PackageManagement.UI/Models/DetailControlModel.cs
Show resolved
Hide resolved
* disable install/update package button for CPM projects in PM UI
Bug
Fixes: NuGet/Home#12229
Regression? Last working version:
Description
Floating versions is not enabled for CPM, this change disables this functionality of the combobox.
Project Level
Solution Level
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation