From 3d884a9b844ff2655b276e27c708fda61803487b Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Thu, 9 Feb 2017 14:06:26 -0800 Subject: [PATCH] Don't cache package information for non-C#/VB languages. --- .../PackageInstallerServiceFactory.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs index 6535e622b80..51264ba221f 100644 --- a/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs +++ b/src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs @@ -30,7 +30,7 @@ namespace Microsoft.VisualStudio.LanguageServices.Packaging /// /// Free threaded wrapper around the NuGet.VisualStudio STA package installer interfaces. /// We want to be able to make queries about packages from any thread. For example, the - /// add-nuget-reference feature wants to know what packages a project already has + /// add-NuGet-reference feature wants to know what packages a project already has /// references to. NuGet.VisualStudio provides this information, but only in a COM STA /// manner. As we don't want our background work to bounce and block on the UI thread /// we have this helper class which queries the information on the UI thread and caches @@ -391,23 +391,34 @@ private void ProcessProjectChange(Solution solution, ProjectId projectId) // Remove anything we have associated with this project. _projectToInstalledPackageAndVersion.TryRemove(projectId, out var installedPackages); - if (!solution.ContainsProject(projectId)) + var project = solution.GetProject(projectId); + if (project == null) { // Project was removed. Nothing needs to be done. return; } + // We really only need to know the NuGet status for managed language projects. + // Also, the NuGet APIs may throw on some projects that don't implement the + // full set of DTE APIs they expect. So we filter down to just C# and VB here + // as we know these languages are safe to build up this index for. + if (project.Language != LanguageNames.CSharp && + project.Language != LanguageNames.VisualBasic) + { + return; + } + // Project was changed in some way. Let's go find the set of installed packages for it. var dteProject = _workspace.TryGetDTEProject(projectId); if (dteProject == null) { - // Don't have a DTE project for this project ID. not something we can query nuget for. + // Don't have a DTE project for this project ID. not something we can query NuGet for. return; } installedPackages = new Dictionary(); - // Calling into nuget. Assume they may fail for any reason. + // Calling into NuGet. Assume they may fail for any reason. try { var installedPackageMetadata = _packageServices.GetInstalledPackages(dteProject); @@ -518,7 +529,7 @@ public void ShowManagePackagesDialog(string packageName) } // We're able to launch the package manager (with an item in its search box) by - // using the IVsSearchProvider API that the nuget package exposes. + // using the IVsSearchProvider API that the NuGet package exposes. // // We get that interface for it and then pass it a SearchQuery that effectively // wraps the package name we're looking for. The NuGet package will then read -- GitLab