public void MenuItemCallback(object sender, EventArgs e) { if (ShowErrorMessageAndReturnTrueIfNoSolutionOpen()) { return; } var dte = Package.GetGlobalService(typeof(DTE)) as DTE; IVsSolution4 solutionService4 = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution4; var projects = SlnFileParser.GetProjectNamesToGuidsDict(dte.Solution.FileName); foreach (var proj in projects.Values) { var guid = new Guid(proj); var res = solutionService4.ReloadProject(ref guid); //ErrorHandler.ThrowOnFailure(res); } string message = "Load all projects complete"; // Show a message box to prove we were here VsShellUtilities.ShowMessageBox( this.ServiceProvider, message, ProjectFocuserCommandPackage.MessageBoxName, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); }
public void AddIceBuilderToProject(EnvDTE.Project p) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName); if (MSBuildUtils.AddIceBuilderToProject(project)) { if (DTEUtil.IsCppProject(p)) { VCUtil.SetupSliceFilter(p); } else { String includeDirectories = ProjectUtil.GetProperty(p, PropertyNames.IncludeDirectories); if (String.IsNullOrEmpty(includeDirectories)) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, @"$(IceHome)\slice"); } else if (includeDirectories.IndexOf(@"$(IceHome)\slice") == -1) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, String.Format(@"$(IceHome)\slice;{0}", includeDirectories)); } ProjectUtil.AddAssemblyReference(p, "Ice"); } p.Save(); IVsHierarchy hier = DTEUtil.GetIVsHierarchy(p); Guid projectGUID = Guid.Empty; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); IVsSolution4.ReloadProject(ref projectGUID); } }
void ReloadProject(IVsSolution4 solution, Guid projectGuid) { ThreadHelper.ThrowIfNotOnUIThread(); int hr; hr = solution.ReloadProject(ref projectGuid); ErrorHandler.ThrowOnFailure(hr); }
public static void Reload(System.IServiceProvider serviceProvider, EnvDTE.Project project) { System.Guid projectGuid = GetProjectGuid(serviceProvider, project); IVsSolution4 solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution4; ErrorHandler.ThrowOnFailure(solution.UnloadProject(ref projectGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser)); ErrorHandler.ThrowOnFailure(solution.ReloadProject(ref projectGuid)); }
public void ReloadProject(IVsProject project) { IVsHierarchy hier = project as IVsHierarchy; Guid projectGUID = Guid.Empty; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution4.UnloadProject(projectGUID, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); IVsSolution4.ReloadProject(ref projectGUID); }
private void RemoveIceBuilderFromProject(IVsProject p) { String path = ProjectUtil.GetProjectFullPath(p); foreach (IVsProject p1 in _buildProjects) { if (path.Equals(ProjectUtil.GetProjectFullPath(p1))) { _buildProjects.Remove(p1); break; } } ProjectUtil.DeleteItems( ProjectUtil.GetGeneratedFiles(p).Aggregate( new List <String>(), (items, kv) => { items.AddRange(kv.Value); return(items); })); if (DTEUtil.IsCSharpProject(p)) { Directory.GetFiles(GetAssembliesDir(GetIceHome()), "*.dll") .ToList() .ForEach(item => { String name = Path.GetFileNameWithoutExtension(item); if (ProjectUtil.HasAssemblyReference(DTEUtil.GetProject(p as IVsHierarchy), name)) { ProjectUtil.RemoveAssemblyReference(DTEUtil.GetProject(p as IVsHierarchy), name); } }); } Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(path, DTEUtil.IsCppProject(p), true); MSBuildUtils.RemoveIceBuilderFromProject(project); ProjectUtil.SaveProject(p); Guid projectGUID = Guid.Empty; IVsHierarchy hier = p as IVsHierarchy; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); try { ProjectCollection.GlobalProjectCollection.UnloadProject(project); } catch (System.Exception) { //expected if the project is not in the global project collection } IVsSolution4.ReloadProject(ref projectGUID); }
protected override void ReloadProject() { IVsSolution4 solution4 = VsSolution as IVsSolution4; VsSolution.GetProjectOfUniqueName(DteProject.UniqueName, out IVsHierarchy hierarchy); int hr = 0; hierarchy.GetGuidProperty(Constants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out Guid guid); ErrorHandler.ThrowOnFailure(hr); solution4.UnloadProject(guid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); solution4.ReloadProject(guid); }
public static void ReloadProject(Guid projectGuid) { if (projectGuid == Guid.Empty) { return; } IVsSolution4 solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution4; int hr; hr = solution.ReloadProject(ref projectGuid); ErrorHandler.ThrowOnFailure(hr); }
private static void ReloadProject([NotNull] Dispatcher dispatcher, [NotNull] IVsSolution4 solution, int retry, Guid projectGuid) { var hr = solution.ReloadProject(ref projectGuid); if (hr == 0) { return; } if (retry < 3) { dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () => ReloadProject(dispatcher, solution, retry + 1, projectGuid)); } }
/// <summary> /// Load the project identified by projectName. /// </summary> /// <param name="solution4"></param> /// <param name="projectName"></param> private static void LoadProject(IVsSolution4 solution4, string projectName) { var project = projects[projectName]; var guid = project.Guid; // Check ProjectGuid (skip if found) if (projectGuids.Contains(guid)) { return; } // Diagnostics Debug.WriteLine($"Loading {projectName}"); // Iterate Project References and load those foreach (XmlNode projectReference in project.XmlDocument.GetElementsByTagName("ProjectReference")) { // Get next Project Name projectName = projectReference["Name"]?.InnerText; // No Name field? Try Name attribute if (projectName == null) { projectName = projectReference.Attributes["Name"]?.Value; } // No Name field? Try Include attribute if (projectName == null) { projectName = projectReference.Attributes["Include"]?.Value?.Between("\\", ".csproj"); } // Skip Projects that have no Name if (projectName == null) { continue; } // Extract Project Name of Reference and call LoadProject recursively LoadProject(solution4, projectName); } // Reload Target Project in Visual Studio int res = solution4.ReloadProject(ref guid); // Store Guid (to prevent duplicate loads) projectGuids.Add(guid); }
public void LoadProject(ProjectDescriptor project) { Dispatcher.CurrentDispatcher.VerifyAccess(); Guid projectId = project.Id; WriteLog($"Loading project \"{project.Name ?? project.Id.ToString()}\""); try { ErrorHandler.ThrowOnFailure(m_solution4.ReloadProject(ref projectId)); } catch (Exception ex) { WriteLog($"Error: Failed to load project \"{project.Name ?? project.Id.ToString()}\"; {ex.Message}"); } }
private static void ReloadProject(Dispatcher dispatcher, IVsSolution4 solution, int retry, Guid projectGuid) { Contract.Requires(dispatcher != null); Contract.Requires(solution != null); var hr = solution.ReloadProject(ref projectGuid); if (hr == 0) { return; } if (retry < 3) { dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () => ReloadProject(dispatcher, solution, retry + 1, projectGuid)); } }
public bool EnsureProjectLoaded(Guid project, bool recursive) { IVsSolution4 sln = GetService <IVsSolution4>(typeof(SVsSolution)); if (sln == null) { return(false); } if (recursive) { return(VSErr.Succeeded(sln.EnsureProjectIsLoaded(ref project, (uint)__VSBSLFLAGS.VSBSLFLAGS_None))); } else { return(VSErr.Succeeded(sln.ReloadProject(ref project))); } }
public void SaveProject(IVsProject project) { Microsoft.Build.Evaluation.Project msproject = project.GetMSBuildProject(true); IVsHierarchy hier = project as IVsHierarchy; Guid projectGUID = Guid.Empty; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution4.UnloadProject(projectGUID, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); msproject.Save(); try { ProjectCollection.GlobalProjectCollection.UnloadProject(msproject); } catch (Exception) { //expected if the project is not in the global project collection } IVsSolution4.ReloadProject(ref projectGUID); }
public void TestUnloadReloadOfProject() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { //Get the global service provider and the dte IServiceProvider sp = VsIdeTestHostContext.ServiceProvider; DTE dte = (DTE)sp.GetService(typeof(DTE)); string destination = Path.Combine(TestContext.TestDir, TestContext.TestName); ProjectNode project = Utilities.CreateMyNestedProject(sp, dte, TestContext.TestName, destination, true); Utilities.SelectOrUnselectNodes <ProjectNode>(project, true); // Save everything. IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution)); solutionService.SaveSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, project.InteropSafeIVsHierarchy, 0); // Unload the project IVsSolution4 solutionService4 = solutionService as IVsSolution4; Assert.IsNotNull(solutionService4, "IVsSolution4 should be implemented!"); solutionService4.UnloadProject(project.ProjectIDGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); Assert.IsTrue(project.IsClosed, "The project has not been unloaded"); // Reload the project solutionService4.ReloadProject(project.ProjectIDGuid); // Check to see if the project is reloaded. we cannot use the instance for the project since that is zombied at this point. IVsHierarchy ourHierarchy; string projectFullpath = project.GetMkDocument(); solutionService.GetProjectOfUniqueName(projectFullpath, out ourHierarchy); Assert.IsTrue(ourHierarchy is IProjectEventsListener, "Our hierarchy has not been reloaded successfully"); // Check to see if the nested project is there. EnvDTE.Project projectDTE = Utilities.GetAutomationObject(ourHierarchy); Assert.IsNotNull(projectDTE.ProjectItems.Item("ANestedProject"), "The nested project has not been loaded correctly."); // Check that bug 106520 does not happen anymore. We will check that the parent project is not dirty. int isDirty; ((IPersistFileFormat)ourHierarchy).IsDirty(out isDirty); Assert.IsTrue(isDirty == 0, "The parent project is dirtied after it has been reloaded"); }); }
public void MenuItemCallback(object sender, EventArgs e) { if (ShowErrorMessageAndReturnTrueIfNoSolutionOpen()) { return; } var dte = Package.GetGlobalService(typeof(DTE)) as DTE; IVsSolution4 solutionService4 = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution4; var projects = FileParser.GetProjects(dte.Solution.FileName); foreach (var proj in projects.Values) { Guid guid = proj.Guid; var res = solutionService4.ReloadProject(ref guid); } }
private void RemoveIceBuilderFromProject(EnvDTE.Project p) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName); MSBuildUtils.RemoveIceBuilderFromProject(project); foreach (EnvDTE.Project p1 in _buildProjects) { if (p.FullName.Equals(p.FullName)) { _buildProjects.Remove(p1); break; } } ProjectUtil.DeleteItems(p, ProjectUtil.GetGeneratedFiles(p).Aggregate( new List <String>(), (items, kv) => { items.AddRange(kv.Value); return(items); })); Directory.GetFiles(GetAssembliesDir(GetIceHome()), "*.dll") .ToList() .ForEach(item => { String name = Path.GetFileNameWithoutExtension(item); if (ProjectUtil.HasAssemblyReference(p, name)) { ProjectUtil.RemoveAssemblyReference(p, name); } }); p.Save(); Guid projectGUID = Guid.Empty; IVsHierarchy hier = DTEUtil.GetIVsHierarchy(p); IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); IVsSolution4.ReloadProject(ref projectGUID); }
/// <summary> /// Reload the project /// </summary> public async Task <bool> ReloadAsync() { await Task.Delay(250); try { ThreadHelper.ThrowIfNotOnUIThread(); _solutionService4.UnloadProject(ref _projectGuid, (int)_VSProjectUnloadStatus.UNLOADSTATUS_LoadPendingIfNeeded); await Task.Delay(250); _solutionService4.ReloadProject(ref _projectGuid); await Task.Delay(250); _solutionService4.EnsureProjectIsLoaded(ref _projectGuid, (int)__VSBSLFLAGS.VSBSLFLAGS_None); return(true); } catch (Exception) { return(false); } }
public void AddIceBuilderToProject(IVsProject p) { Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), true); if (MSBuildUtils.AddIceBuilderToProject(project)) { if (DTEUtil.IsCppProject(p)) { VCUtil.SetupSliceFilter(DTEUtil.GetProject(p as IVsHierarchy)); } else { String includeDirectories = ProjectUtil.GetProperty(p, PropertyNames.IncludeDirectories); if (String.IsNullOrEmpty(includeDirectories)) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, @"$(IceHome)\slice"); } else if (includeDirectories.IndexOf(@"$(IceHome)\slice") == -1) { ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, String.Format(@"$(IceHome)\slice;{0}", includeDirectories)); } ProjectUtil.AddAssemblyReference(DTEUtil.GetProject(p as IVsHierarchy), "Ice"); } ProjectUtil.SaveProject(p); IVsHierarchy hier = p as IVsHierarchy; Guid projectGUID = Guid.Empty; IVsSolution.GetGuidOfProject(hier, out projectGUID); IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0); project.Save(); try { ProjectCollection.GlobalProjectCollection.UnloadProject(project); } catch (System.Exception) { //expected if the project is not in the global project collection } IVsSolution4.ReloadProject(ref projectGUID); } }
public static void EnsureProjectsLoadedByNames(DTE dte, HashSet <string> allProjectNamesToLoad, bool unloadUnusedProjects) { IVsSolution4 solutionService4 = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution4; var projects = FileParser.GetProjects(dte.Solution.FileName); foreach (var project in projects.Values) { var shouldBeLoaded = allProjectNamesToLoad.Contains(project.Name); var guid = project.Guid; int res = 0; if (shouldBeLoaded) { res = solutionService4.ReloadProject(ref guid); } else if (unloadUnusedProjects && !shouldBeLoaded) { res = solutionService4.UnloadProject(ref guid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); } } }
public int ReloadProject(ref Guid guidProjectID) { return(_solution.ReloadProject(ref guidProjectID)); }
public void ModifyUnityBuildXML(string projFileName, string slnFileName, bool unitybuild, string uniqueName, bool settingMenuProject) { Guid guid = new Guid(); string solutionName = slnFileName; object solutionObject = null; IRunningObjectTable rot; System.Runtime.InteropServices.ComTypes.IEnumMoniker enumMoniker; int retVal = GetRunningObjectTable(0, out rot); if (retVal == 0) { rot.EnumRunning(out enumMoniker); enumMoniker.Reset(); IntPtr fetched = IntPtr.Zero; System.Runtime.InteropServices.ComTypes.IMoniker[] moniker = new System.Runtime.InteropServices.ComTypes.IMoniker[1]; while (enumMoniker.Next(1, moniker, fetched) == 0) { IBindCtx bindCtx; CreateBindCtx(0, out bindCtx); string displayName; moniker[0].GetDisplayName(bindCtx, null, out displayName); bool isPrebuildSolution = displayName.Contains(solutionName); if (isPrebuildSolution) { rot.GetObject(moniker[0], out solutionObject); break; } } } if (solutionObject != null) { Solution solution = solutionObject as Solution; EnvDTE.DTE dte = solution.DTE; Array projectsObject = (Array)dte.ActiveSolutionProjects; Project project; ServiceProvider serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte); IVsSolution vsSolution = (IVsSolution)serviceProvider.GetService(typeof(IVsSolution)); if (vsSolution == null) { return; } IVsHierarchy vsHierarchy = null; if (uniqueName == null) { project = projectsObject.GetValue(0) as Project; vsSolution.GetProjectOfUniqueName(project.UniqueName, out vsHierarchy); } else { vsSolution.GetProjectOfUniqueName(uniqueName, out vsHierarchy); } vsSolution.GetGuidOfProject(vsHierarchy, out guid); IVsSolution4 vsSolution4 = (IVsSolution4)serviceProvider.GetService(typeof(SVsSolution)); vsSolution4.UnloadProject(guid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); ///////////////////////////////// xml수정 /////////////////////////////// if (settingMenuProject) { int unitybuildMenuValue = SetUnitybuildEnableInfo(projFileName); SetUnitybuildMenuinfo(unitybuildMenuValue); } if (unitybuild == true && settingMenuProject == false) { SettingEnableUnityBuild(projFileName); } else if (unitybuild == false && settingMenuProject == false) { SettingDisableUnityBuild(projFileName); } /////////////////////////////// xml수정 /////////////////////////////// vsSolution4.ReloadProject(guid); } }
public static int LoadProject(IVsSolution4 solution, Guid projectGuid) { return(solution.ReloadProject(ref projectGuid)); }
/// <summary> /// Reload the project /// </summary> public void Reload() { _solutionService4.ReloadProject(ref _projectGuid); }
/// <summary> /// Reload the project /// </summary> public void Reload() { ThreadHelper.ThrowIfNotOnUIThread(); _solutionService4.ReloadProject(ref _projectGuid); }
void NewProjCreated_AfterExecute(string Guid, int ID, object CustomIn, object CustomOut) { // if we are here - new project created string newProjFullName = string.Empty; if (beforeAddProjsCont != null) { if (Globals.dte.Solution.Projects.Count > beforeAddProjsCont.Count) { SortedSet <EnvDTE.Project> afterAddProjsCont; AddExistingCPPProjs(out afterAddProjsCont); if (afterAddProjsCont.Count > beforeAddProjsCont.Count) { IEnumerable <EnvDTE.Project> newProjs = afterAddProjsCont.Except(beforeAddProjsCont); newProjFullName = newProjs.First().FullName; } } } else { foreach (EnvDTE.Project proj in Globals.dte.Solution.Projects) { if (proj.Kind == "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" && proj.Name != "Miscellaneous Files") { newProjFullName = proj.FullName; break; } } } if (newProjFullName != string.Empty) { IVsSolution4 vsSolution4 = vsSolution as IVsSolution4; IVsHierarchy projObj; vsSolution.GetProjectOfUniqueName(newProjFullName, out projObj); System.Guid projGuid = System.Guid.Empty; vsSolution.GetGuidOfProject(projObj, out projGuid); vsSolution4.UnloadProject(projGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_LoadPendingIfNeeded); Globals.orchestrator.Orchestrate(newProjFullName); vsSolution4.ReloadProject(projGuid); } ///////////////////////////////////////// //Globals.orchestrator.InitSolutionConfigurations(); //IVsSolution4 vsSolution4 = GetService(typeof(SVsSolution)) as IVsSolution4; //IVsSolution vsSolution = vsSolution4 as IVsSolution; //IEnumHierarchies hierarchies; //vsSolution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLPROJECTS/*EPF_MATCHTYPE*/, System.Guid.Empty, out hierarchies); //IVsHierarchy[] foundHierarchies = new IVsHierarchy[1]; //uint count; //while (hierarchies.Next(1, foundHierarchies, out count) == VSConstants.S_OK && count == 1) //{ // IVsProject vsProj = foundHierarchies[0] as IVsProject; // EnvDTE.Project proj = null; // object propProjObj = null; // foundHierarchies[0].GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out propProjObj); // if (propProjObj != null) // proj = propProjObj as EnvDTE.Project; // System.Guid projGuid = System.Guid.Empty; // vsSolution.GetGuidOfProject(foundHierarchies[0], out projGuid); // if (proj != null && proj.Kind == "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" && proj.Name != "Miscellaneous Files") // { // string projName = proj.FullName; // vsSolution4.UnloadProject(projGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_LoadPendingIfNeeded); // Globals.orchestrator.Orchestrate(projName); // vsSolution4.ReloadProject(projGuid); // } //} ////if (VsSolutionEvents.newProjFullPath != null) ////{ //// vsSolution4.UnloadProject(VsSolutionEvents.newProjGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_LoadPendingIfNeeded); //// Globals.orchestrator.Orchestrate(VsSolutionEvents.newProjFullPath); //// vsSolution4.ReloadProject(VsSolutionEvents.newProjGuid); ////} }