예제 #1
0
        /// <summary>
        /// Checks the SlowCheetah NuGet package on current project.
        /// If no version is installed, prompts for install of latest version;
        /// if an older version is detected, shows update information.
        /// </summary>
        /// <param name="hierarchy">Hierarchy of the project to be verified</param>
        public void CheckSlowCheetahInstallation(IVsHierarchy hierarchy)
        {
            if (hierarchy == null)
            {
                throw new ArgumentNullException(nameof(hierarchy));
            }

            Project currentProject = PackageUtilities.GetAutomationFromHierarchy <Project>(hierarchy, (uint)VSConstants.VSITEMID.Root);

            // Whether or not an even older version of SlowCheetah (before NuGet) is installed
            bool isOldScInstalled = IsOldSlowCheetahInstalled(hierarchy as IVsBuildPropertyStorage);

            if (isOldScInstalled)
            {
                this.UpdateSlowCheetah(currentProject);
            }
            else if (!this.IsSlowCheetahInstalled(currentProject))
            {
                // If SlowCheetah is not installed at all
                this.BackgroundInstallSlowCheetah(currentProject);
            }
            else if (!this.IsSlowCheetahUpdated(currentProject))
            {
                // In this case, an older NuGet package is installed,
                // but traces of old SlowCheetah installation were not found
                // This means the user may have manually edited their project file.
                // In this case, show the update information so that they know the proper way to uninstall
                INugetPackageHandler nugetHandler = NugetHandlerFactory.GetHandler(this.package);
                nugetHandler.ShowUpdateInfo();
            }
        }
        /// <summary>
        /// Gets the appropriate <see cref="INugetPackageHandler"/> depending on the user's Visual Stuido version
        /// </summary>
        /// <param name="package">Visual Studio Package</param>
        /// <returns>The correct handler</returns>
        public static INugetPackageHandler GetHandler(IServiceProvider package)
        {
            if (handler == null)
            {
                EnvDTE.DTE dte         = ProjectUtilities.GetDTE();
                bool       showInfoBar = false;
                if (Version.TryParse(dte.Version, out Version vsVersion))
                {
                    showInfoBar = vsVersion >= new Version(14, 0);
                }

                if (showInfoBar)
                {
                    handler = new NugetInfoBarHandler(package);
                }
                else
                {
                    handler = new LegacyNugetMessageHandler(package);
                }
            }

            return(handler);
        }