private bool InstallSmartTests(Project project) { if (MessageBox.Show($"SmartTests Extension is installed, but SmartTest package is not installed in project '{project.Name}'.\nDo you want to install it now?", "SmartTests", MessageBoxButton.YesNo) == MessageBoxResult.No) { project.Globals["UseSmartTests"] = "false"; project.Globals.VariablePersists["UseSmartTests"] = true; return(false); } PackageInstaller.InstallLatestPackage(null, project, "SmartTests", false, false); return(true); }
private static async Task PromptToInstallAsync(IEnumerable <Project> projects) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); string msg = $"One or more VSIX projects in this solution aren't using the Microsoft.VisualStudio.SDK.Analyzers NuGet package.\r\rDo you wish to install it now?"; MessageBoxResult answer = MessageBox.Show(msg, Vsix.Name, MessageBoxButton.OKCancel, MessageBoxImage.Question); if (answer == MessageBoxResult.OK) { _dte.StatusBar.Text = $"Installing {_nugetId}..."; IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>(); try { foreach (Project project in projects) { installer.InstallLatestPackage(null, project, _nugetId, false, false); } } catch (Exception ex) { _dte.StatusBar.Text = ex.Message; } _dte.StatusBar.Text = $"VSSDK Analyzers installed successfully"; } }
/// <inheritdoc/> public override void Execute(Project project) { var componentModel = (IComponentModel)this.Package.GetService(typeof(SComponentModel)); IVsPackageInstaller2 packageInstaller = componentModel.GetService <IVsPackageInstaller2>(); packageInstaller.InstallLatestPackage(null, project, SlowCheetahNuGetManager.PackageName, false, false); this.Successor.Execute(project); }
private void BackgroundInstallSlowCheetah(Project project) { string projName = project.UniqueName; bool needInstall = true; lock (this.syncObject) { needInstall = this.installTasks.Add(projName); } if (needInstall) { if (this.HasUserAcceptedWarningMessage(Resources.Resources.NugetInstall_Title, Resources.Resources.NugetInstall_Text)) { // Gets the general output pane to inform user of installation IVsOutputWindowPane outputWindow = (IVsOutputWindowPane)this.package.GetService(typeof(SVsGeneralOutputWindowPane)); outputWindow?.OutputString(string.Format(Resources.Resources.NugetInstall_InstallingOutput, project.Name) + Environment.NewLine); // Uninstalls the older version (if present) and installs latest package var componentModel = (IComponentModel)this.package.GetService(typeof(SComponentModel)); IVsPackageInstaller2 packageInstaller = componentModel.GetService <IVsPackageInstaller2>(); TPL.Task.Run(() => { string outputMessage = Resources.Resources.NugetInstall_FinishedOutput; try { packageInstaller.InstallLatestPackage(null, project, PackageName, false, false); } catch { outputMessage = Resources.Resources.NugetInstall_ErrorOutput; throw; } finally { lock (this.syncObject) { this.installTasks.Remove(projName); } ThreadHelper.Generic.BeginInvoke(() => outputWindow?.OutputString(string.Format(outputMessage, project.Name) + Environment.NewLine)); } }); } else { lock (this.syncObject) { // If the user refuses to install, the task should not be added this.installTasks.Remove(projName); } } } }
private void Execute(object sender, EventArgs e) { ProjectItem item = VsHelpers.DTE.SelectedItems.Item(1).ProjectItem; try { var dependencies = Dependencies.FromConfigFile(item.FileNames[1]); IEnumerable <string> packageIds = dependencies.Providers.Select(p => p.NuGetPackageId).Distinct(); if (!_isPackageInstalled) { if (!UserWantsToInstall()) { return; } System.Threading.Tasks.Task.Run(() => { Logger.LogEvent("Installing NuGet package containing MSBuild target...", LogLevel.Status); foreach (string packageId in packageIds) { IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>(); installer.InstallLatestPackage(null, item.ContainingProject, packageId, true, false); } Telemetry.TrackUserTask("InstallNugetPackage"); Logger.LogEvent("NuGet package installed", LogLevel.Status); }); } else { System.Threading.Tasks.Task.Run(() => { Logger.LogEvent("Uninstalling NuGet package...", LogLevel.Status); foreach (string packageId in packageIds) { IVsPackageUninstaller uninstaller = _componentModel.GetService <IVsPackageUninstaller>(); uninstaller.UninstallPackage(item.ContainingProject, packageId, false); } Telemetry.TrackUserTask("UninstallNugetPackage"); Logger.LogEvent("NuGet package uninstalled", LogLevel.Status); }); } } catch (Exception ex) { Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex); Logger.LogEvent("Error installing NuGet package", LogLevel.Status); } }
private void UpdateSlowCheetah(Project project) { // This is done on the UI thread because changes are made to the project file, // causing it to be reloaded. To avoid conflicts with NuGet installation, // the update is done sequentially if (this.HasUserAcceptedWarningMessage(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text)) { // Creates dialog informing the user to wait for the installation to finish IVsThreadedWaitDialogFactory twdFactory = this.package.GetService(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory; IVsThreadedWaitDialog2 dialog = null; twdFactory?.CreateInstance(out dialog); string title = Resources.Resources.NugetUpdate_WaitTitle; string text = Resources.Resources.NugetUpdate_WaitText; dialog?.StartWaitDialog(title, text, null, null, null, 0, false, true); try { // Installs the latest version of the SlowCheetah NuGet package var componentModel = (IComponentModel)this.package.GetService(typeof(SComponentModel)); if (this.IsSlowCheetahInstalled(project)) { IVsPackageUninstaller packageUninstaller = componentModel.GetService <IVsPackageUninstaller>(); packageUninstaller.UninstallPackage(project, PackageName, true); } IVsPackageInstaller2 packageInstaller = componentModel.GetService <IVsPackageInstaller2>(); packageInstaller.InstallLatestPackage(null, project, PackageName, false, false); project.Save(); ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName); foreach (ProjectPropertyGroupElement propertyGroup in projectRoot.PropertyGroups.Where(pg => pg.Label.Equals("SlowCheetah"))) { projectRoot.RemoveChild(propertyGroup); } foreach (ProjectImportElement import in projectRoot.Imports.Where(i => i.Label == "SlowCheetah" || i.Project == "$(SlowCheetahTargets)")) { projectRoot.RemoveChild(import); } projectRoot.Save(); } finally { // Closes the wait dialog. If the dialog failed, does nothing int canceled; dialog?.EndWaitDialog(out canceled); } } }
//packageInstaller.InstallLatestPackage(null, currentProject,"Newtonsoft.Json", false, false); public static void InstallPackageToProject(Project project, string packageId) { //PackageInstallerServices.in try { OutputHelper.OutputMessageToPane($"准备{packageId}安装包到项目"); string versionString = GetVersionOfPackage(project, packageId); OutputHelper.OutputMessageToPane($"更新包:{packageId}到项目{project.Name},原始版本是{versionString}"); PackageInstaller.InstallLatestPackage(source, project, packageId, false, false); OutputHelper.OutputMessageToPane($"安装包{packageId}到项目成功"); } catch (Exception e) { OutputHelper.OutputMessageToPane($"安装包{packageId}到项目失败,原因是:{e.Message}"); } }
private void Execute(object sender, EventArgs e) { ProjectItem item = VsHelpers.DTE.SelectedItems.Item(1).ProjectItem; try { if (!_isPackageInstalled) { if (!UserWantsToInstall()) { return; } System.Threading.Tasks.Task.Run(() => { Logger.LogEvent("Installing NuGet package containing MSBuild target...", LogLevel.Status); IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>(); installer.InstallLatestPackage(null, item.ContainingProject, Constants.NuGetPackageId, true, false); Telemetry.TrackUserTask("InstallNugetPackage"); Logger.LogEvent("NuGet package installed", LogLevel.Status); }); } else { System.Threading.Tasks.Task.Run(() => { Logger.LogEvent("Uninstalling NuGet package...", LogLevel.Status); IVsPackageUninstaller uninstaller = _componentModel.GetService <IVsPackageUninstaller>(); uninstaller.UninstallPackage(item.ContainingProject, Constants.NuGetPackageId, false); Telemetry.TrackUserTask("UninstallNugetPackage"); Logger.LogEvent("NuGet package uninstalled", LogLevel.Status); }); } } catch (Exception ex) { Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex); Logger.LogEvent("Error installing NuGet package", LogLevel.Status); } }
private async Task ExecuteAsync(object sender, EventArgs e) { ProjectItem projectItem = await VsHelpers.GetSelectedItemAsync(); Project project = await VsHelpers.GetProjectOfSelectedItemAsync(); try { var dependencies = _dependenciesFactory.FromConfigFile(projectItem.FileNames[1]); IEnumerable <string> packageIds = dependencies.Providers .Where(p => p.NuGetPackageId != null) .Select(p => p.NuGetPackageId) .Distinct(); if (!_isPackageInstalled) { if (!UserWantsToInstall()) { return; } await Task.Run(() => { Logger.LogEvent(Resources.Text.Nuget_InstallingPackage, LogLevel.Status); try { foreach (string packageId in packageIds) { IVsPackageInstaller2 installer = _componentModel.GetService <IVsPackageInstaller2>(); installer.InstallLatestPackage(null, project, packageId, true, false); } Telemetry.TrackUserTask("Install-NugetPackage"); Logger.LogEvent(Resources.Text.Nuget_PackageInstalled, LogLevel.Status); } catch (Exception ex) { Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex); Logger.LogEvent(Resources.Text.Nuget_PackageFailedToInstall, LogLevel.Status); } }); } else { await Task.Run(() => { Logger.LogEvent(Resources.Text.Nuget_UninstallingPackage, LogLevel.Status); try { foreach (string packageId in packageIds) { IVsPackageUninstaller uninstaller = _componentModel.GetService <IVsPackageUninstaller>(); uninstaller.UninstallPackage(project, packageId, false); } Telemetry.TrackUserTask("Uninstall-NugetPackage"); Logger.LogEvent(Resources.Text.Nuget_PackageUninstalled, LogLevel.Status); } catch (Exception ex) { Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex); Logger.LogEvent(Resources.Text.Nuget_PackageFailedToUninstall, LogLevel.Status); } }); } } catch (Exception ex) { Telemetry.TrackException(nameof(RestoreOnBuildCommand), ex); Logger.LogEvent(Resources.Text.Nuget_PackageFailedToInstall, LogLevel.Status); } }
public void InstallLatestPackage(string source, EnvDTE.Project project, string packageId, bool includePrerelease, bool ignoreDependencies) => _packageInstaller.InstallLatestPackage(source, project, packageId, includePrerelease, ignoreDependencies);