Search code examples
c#visual-studiovisual-studio-extensionsvs-extensibility

Visual Studio Extension - Event after NuGet install/uninstall?


I'm developing a Visual Studio extension, and I'd like to execute some logic after a NuGet install or uninstall. Is there an event that I can monitor for this? I've tried the OnItemAdded and OnItemDeleted in the IVsHierarchy interface, but the issue here is that it will execute numerous times per install/uninstall due to the number of files that are being added or removed to the solution. I'd like to trigger the event after the NuGet process is complete.


Solution

  • You can use NuGet API in Visual Studio and listen to NuGet events like PackageInstalling or PackageInstalled. But make sure you use these events in batch mode and also listens to BatchStart and BatchEnd from NuGet IVsPackageInstallerProjectEvents interface so that it doesn't degrade NuGet performance.

    You can find more details about these APIs here at NuGet blogpost.

    So ideally when you receive BatchStart event, you will hold on to execute IVsPackageInstallerEvents events like PackageInstalling, PackageInstalled, etc and apply these after you receive BatchEnd event.