aspnet / LibraryManager

Other
446 stars 78 forks source link

Switch away from deprecated NuGet API #716

Open jimmylewis opened 10 months ago

jimmylewis commented 10 months ago

The IVsPackageInstallerServices interface is marked deprecated for getting installed package info, due to threading problems within NuGet. Switched to the new interface instead.

jimmylewis commented 9 months ago

While doing some further testing with this, it seems really flaky. Now that the work of detecting package installation is async, it seems that the OleMenuCommand is not waiting for it to finish - it will use stale text for the menu command. I'm seeing this in the debugger where the context menu appears between stepping through these lines:

button.Visible = true;
button.Enabled = KnownUIContexts.SolutionExistsAndNotBuildingAndNotDebuggingContext.IsActive;
_isPackageInstalled = await IsPackageInstalledAsync(projectGuid);
// context menu is shown before the following lines are executed:
if (_isPackageInstalled)
{
    button.Text = Resources.Text.DisableRestoreOnBuild;
}
else
{
    button.Text = Resources.Text.EnableRestoreOnBuild;
}

I also tried moving the button.Visible = true to after the await, and the command was never visible again. So I'm guessing that the QueryStatus has a timeout, and this new operation is taking too long; it's getting the first half of the changes (button.Visible) but not the second (button.Text).

I tried caching the text to use, thinking I could make up for it, but that revealed that the NuGet API is actually pretty laggy. After executing an install/uninstall operation, it takes several seconds for it to return an updated result (which different from the old implementation, which seemed to update immediately). I'll need to follow up with someone from NuGet to understand why this API seems much flakier.