private bool IsNuGetInstalled()
        {
            if (_nugetInstallStatusForCurrentSolution != FxCopAnalyzersInstallStatus.Installed)
            {
                var activeDocumentId = _documentTrackingService.TryGetActiveDocument();
                if (activeDocumentId == null)
                {
                    return(false);
                }

                var document = _workspace.CurrentSolution.GetTextDocument(activeDocumentId);
                if (document == null)
                {
                    return(false);
                }

                foreach (var analyzerReference in document.Project.AnalyzerReferences)
                {
                    if (ChildAnalyzerNuGetPackageIds.Contains(analyzerReference.Display))
                    {
                        // We set installed to ensure we don't go through this again next time a
                        // suggested action is called for any document in current solution.
                        _nugetInstallStatusForCurrentSolution = FxCopAnalyzersInstallStatus.Installed;
                        return(true);
                    }
                }
            }

            return(false);
        }
        private bool IsNuGetInstalled(out bool hasUnresolvedAnalyzerReference)
        {
            hasUnresolvedAnalyzerReference = false;
            if (_nugetInstallStatusForCurrentSolution != FxCopAnalyzersInstallStatus.Installed)
            {
                var activeDocumentId = _documentTrackingService.TryGetActiveDocument();
                if (activeDocumentId == null)
                {
                    return(false);
                }

                var document = _workspace.CurrentSolution.GetTextDocument(activeDocumentId);
                if (document == null)
                {
                    return(false);
                }

                if (IsNuGetInstalled(document.Project.AnalyzerReferences, out hasUnresolvedAnalyzerReference))
                {
                    // We set installed to ensure we don't go through this again next time a
                    // suggested action is called for any document in current solution.
                    _nugetInstallStatusForCurrentSolution = FxCopAnalyzersInstallStatus.Installed;
                    return(true);
                }
            }

            return(false);
        }
 private void OnWorkspaceChanged(object sender, WorkspaceChangeEventArgs eventArgs)
 {
     switch (eventArgs.Kind)
     {
     case WorkspaceChangeKind.SolutionAdded:
         _nugetInstallStatusForCurrentSolution = FxCopAnalyzersInstallStatus.Unknown;
         _infoBarChecked = false;
         break;
     }
 }
        public static void LogVsixInstallationStatus(Workspace workspace, FxCopAnalyzersInstallStatus installStatus)
        {
            var installed = workspace.Options.GetOption(FxCopAnalyzersInstallOptions.VsixInstalled);

            if (!installed && installStatus == FxCopAnalyzersInstallStatus.Installed)
            {
                // first time after vsix installed
                workspace.Options = workspace.Options.WithChangedOption(FxCopAnalyzersInstallOptions.VsixInstalled, true);
                Log("VsixInstalled");
            }

            if (installed && installStatus == FxCopAnalyzersInstallStatus.NotInstalled)
            {
                // first time after vsix is uninstalled
                workspace.Options = workspace.Options.WithChangedOption(FxCopAnalyzersInstallOptions.VsixInstalled, false);
                Log("VsixUninstalled");
            }
        }
        private bool IsVsixInstalled()
        {
            if (_vsixInstallStatus == FxCopAnalyzersInstallStatus.Unknown)
            {
                var vsShell = _serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
                var hr      = vsShell.IsPackageInstalled(FxCopAnalyzersPackageGuid, out var installed);
                if (ErrorHandler.Failed(hr))
                {
                    FatalError.ReportWithoutCrash(Marshal.GetExceptionForHR(hr));

                    // We set installed to ensure we don't go through this again next time a
                    // suggested action is called, and we don't want to continue if the shell
                    // is busted.
                    _vsixInstallStatus = FxCopAnalyzersInstallStatus.Installed;
                }
                else
                {
                    _vsixInstallStatus = installed != 0 ? FxCopAnalyzersInstallStatus.Installed : FxCopAnalyzersInstallStatus.NotInstalled;
                    FxCopAnalyzersInstallLogger.LogVsixInstallationStatus(_workspace, _vsixInstallStatus);
                }
            }

            return(_vsixInstallStatus == FxCopAnalyzersInstallStatus.Installed);
        }