/// <summary> /// Return all possibly valid project names in the current solution. This includes all /// unique names and safe names. /// </summary> /// <returns></returns> protected IEnumerable <string> GetAllValidProjectNames() { var safeNames = _solutionManager.GetProjects().Select(p => _solutionManager.GetProjectSafeName(p)); var uniqueNames = _solutionManager.GetProjects().Select(p => p.GetCustomUniqueName()); return(uniqueNames.Concat(safeNames).Distinct()); }
private void EnablePackageRestore(bool fromActivation) { EnsureNuGetBuild(fromActivation); IVsPackageManager packageManager = _packageManagerFactory.CreatePackageManager(); foreach (Project project in _solutionManager.GetProjects()) { EnablePackageRestore(project, packageManager); } }
protected override void ProcessRecordCore() { if (!SolutionManager.IsSolutionOpen) { ErrorHandler.ThrowSolutionNotOpenTerminatingError(); } if (All.IsPresent) { WriteObject(_solutionManager.GetProjects(), enumerateCollection: true); } else { // No name specified; return default project (if not null) if (Name == null) { Project defaultProject = _solutionManager.DefaultProject; if (defaultProject != null) { WriteObject(defaultProject); } } else { // get all projects matching name(s) - handles wildcards WriteObject(GetProjectsByName(Name), enumerateCollection: true); } } }
public string[] GetAvailableProjects() { Debug.Assert(_solutionManager != null); var projectSafeNames = (_solutionManager.GetProjects().Select(p => _solutionManager.GetProjectSafeName(p))).ToArray(); return(projectSafeNames); }
public string[] GetAvailableProjects() { Debug.Assert(_solutionManager != null); var allProjects = _solutionManager.GetProjects(); _projectSafeNames = allProjects.Select(_solutionManager.GetProjectSafeName).ToArray(); var displayNames = allProjects.Select(p => p.GetDisplayName(_solutionManager)).ToArray(); Array.Sort(displayNames, _projectSafeNames, StringComparer.CurrentCultureIgnoreCase); return(displayNames); }
private void SaveProjectCheckStates(IList <Project> selectedProjects) { var selectedProjectSet = new HashSet <Project>(selectedProjects); foreach (Project project in _solutionManager.GetProjects()) { if (!String.IsNullOrEmpty(project.UniqueName)) { bool checkState = selectedProjectSet.Contains(project); _checkStateCache[project.UniqueName] = checkState; } } }
public static void EnsureCheckedOutIfExists(this ISolutionManager solutionManager, string fullPath) { if (File.Exists(fullPath)) { var project = solutionManager.GetProjects().FirstOrDefault(); if ((project != null) && (project.DTE != null) && (project.DTE.SourceControl != null)) { var sourceControl = project.DTE.SourceControl; if (sourceControl.IsItemUnderSCC(fullPath) && !sourceControl.IsItemCheckedOut(fullPath)) { sourceControl.CheckOutItem(fullPath); } } } }
public static void CollapseAllNodes(ISolutionManager solutionManager, IDictionary <string, ISet <VsHierarchyItem> > ignoreNodes) { // this operation needs to execute on UI thread ThreadHelper.Generic.Invoke(() => { foreach (Project project in solutionManager.GetProjects()) { ISet <VsHierarchyItem> expandedNodes; if (ignoreNodes.TryGetValue(project.UniqueName, out expandedNodes) && expandedNodes != null) { CollapseProjectHierarchyItems(project, expandedNodes); } } }); }
public static void CollapseAllNodes(ISolutionManager solutionManager, IDictionary<string, ISet<VsHierarchyItem>> ignoreNodes) { // this operation needs to execute on UI thread ThreadHelper.Generic.Invoke(() => { foreach (Project project in solutionManager.GetProjects()) { ISet<VsHierarchyItem> expandedNodes; if (ignoreNodes.TryGetValue(project.GetUniqueName(), out expandedNodes) && expandedNodes != null) { CollapseProjectHierarchyItems(project, expandedNodes); } } }); }
public static IDictionary <string, ISet <VsHierarchyItem> > GetAllExpandedNodes(ISolutionManager solutionManager) { // this operation needs to execute on UI thread return(ThreadHelper.Generic.Invoke(() => { var results = new Dictionary <string, ISet <VsHierarchyItem> >(StringComparer.OrdinalIgnoreCase); foreach (Project project in solutionManager.GetProjects()) { ICollection <VsHierarchyItem> expandedNodes = GetExpandedProjectHierarchyItems(project); Debug.Assert(!results.ContainsKey(project.UniqueName)); results[project.UniqueName] = new HashSet <VsHierarchyItem>(expandedNodes); } return results; } )); }
public static IDictionary<string, ISet<VsHierarchyItem>> GetAllExpandedNodes(ISolutionManager solutionManager) { // this operation needs to execute on UI thread return ThreadHelper.Generic.Invoke(() => { var results = new Dictionary<string, ISet<VsHierarchyItem>>(StringComparer.OrdinalIgnoreCase); foreach (Project project in solutionManager.GetProjects()) { ICollection<VsHierarchyItem> expandedNodes = GetExpandedProjectHierarchyItems(project); Debug.Assert(!results.ContainsKey(project.GetUniqueName())); results[project.GetUniqueName()] = new HashSet<VsHierarchyItem>(expandedNodes); } return results; } ); }
protected override bool ExecuteCore(PackageItem item) { IPackage package = item.PackageIdentity; // treat solution-level packages specially if (!PackageManager.IsProjectLevel(package)) { return(UninstallSolutionPackage(package)); } // display the Manage dialog to allow user to pick projects to install/uninstall IEnumerable <Project> selectedProjects = _userNotifierServices.ShowProjectSelectorWindow( Resources.Dialog_InstalledSolutionInstruction, item.PackageIdentity, // Selector function to return the initial checkbox state for a Project. // We check a project by default if it has the current package installed. project => PackageManager.GetProjectManager(project).IsInstalled(package), ignored => true); if (selectedProjects == null) { // user presses Cancel button on the Solution dialog return(false); } // bug #1181: Use HashSet<unique name> instead of HashSet<Project>. // in some rare cases, the project instance returned by GetProjects() may be different // than the ones in selectedProjectSet. var selectedProjectsSet = new HashSet <string>( selectedProjects.Select(p => p.GetUniqueName()), StringComparer.OrdinalIgnoreCase); // now determine if user has actually made any change to the checkboxes IList <Project> allProjects = _solutionManager.GetProjects().ToList(); bool hasInstallWork = allProjects.Any(p => selectedProjectsSet.Contains(p.GetUniqueName()) && !IsPackageInstalledInProject(p, package)); bool hasUninstallWork = allProjects.Any(p => !selectedProjectsSet.Contains(p.GetUniqueName()) && IsPackageInstalledInProject(p, package)); if (!hasInstallWork && !hasUninstallWork) { // nothing to do, so return return(false); } var uninstallRepositories = new List <IPackageRepository>(); var uninstallFrameworks = new List <FrameworkName>(); var uninstallProjects = new List <Project>(); bool?removeDepedencies = false; if (hasUninstallWork) { // Starting in 2.0, each project can have a different set of dependencies (because of different target frameworks). // To keep the UI simple, we aggregate all the dependencies from all uninstall projects // and ask if user wants to uninstall them all. foreach (Project project in allProjects) { // check if user wants to uninstall the package in this project if (!selectedProjectsSet.Contains(project.GetUniqueName())) { uninstallProjects.Add(project); uninstallRepositories.Add(PackageManager.GetProjectManager(project).LocalRepository); uninstallFrameworks.Add(project.GetTargetFrameworkName()); } } removeDepedencies = AskRemoveDependency(package, uninstallRepositories, uninstallFrameworks); if (removeDepedencies == null) { // user cancels the operation. return(false); } } ShowProgressWindow(); // now install the packages that are checked // Bug 1357: It's crucial that we perform all installs before uninstalls // to avoid the package file being deleted before an install. if (hasInstallWork) { bool successful = InstallPackageIntoProjects(package, allProjects, selectedProjectsSet); if (!successful) { return(false); } } // now uninstall the packages that are unchecked for (int i = 0; i < uninstallProjects.Count; ++i) { try { CheckDependentPackages(package, uninstallRepositories[i], uninstallFrameworks[i]); UninstallPackageFromProject(uninstallProjects[i], item, (bool)removeDepedencies); } catch (Exception ex) { AddFailedProject(uninstallProjects[i], ex); } } HideProgressWindow(); return(true); }
private void UpdatePackage(string packageId, Action <IProjectManager> projectAction, Func <IPackage> resolvePackage, bool updateDependencies, bool allowPrereleaseVersions, ILogger logger, IPackageOperationEventListener eventListener) { bool appliesToProject; IPackage package = FindLocalPackage(packageId, out appliesToProject); if (appliesToProject) { eventListener = eventListener ?? NullPackageOperationEventListener.Instance; IPackage newPackage = null; foreach (var project in _solutionManager.GetProjects()) { IProjectManager projectManager = GetProjectManager(project); try { InitializeLogger(logger, projectManager); if (projectManager.LocalRepository.Exists(packageId)) { eventListener.OnBeforeAddPackageReference(project); try { RunSolutionAction(() => projectAction(projectManager)); if (newPackage == null) { // after the update, get the new version to add to the recent package repository newPackage = projectManager.LocalRepository.FindPackage(packageId); } } catch (Exception e) { logger.Log(MessageLevel.Error, ExceptionUtility.Unwrap(e).Message); eventListener.OnAddPackageReferenceError(project, e); } finally { eventListener.OnAfterAddPackageReference(project); } } } finally { ClearLogger(projectManager); } } if (newPackage != null) { AddPackageToRecentRepository(newPackage); } } else { // Find the package we're going to update to IPackage newPackage = resolvePackage(); if (newPackage != null && package.Version != newPackage.Version) { try { InitializeLogger(logger, projectManager: null); // We might be updating a solution only package UpdatePackage(newPackage, updateDependencies, allowPrereleaseVersions); } finally { ClearLogger(projectManager: null); } // Add package to recent repository AddPackageToRecentRepository(newPackage); } else { logger.Log(MessageLevel.Info, VsResources.NoUpdatesAvailable, packageId); } } }