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); } }
async Task ConvertProjectAsync(Project project) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsSolution4 solution = await ServiceProvider.GetServiceAsync(typeof(SVsSolution)) as IVsSolution4; ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName); var projectData = ReadProjectData(projectRoot); projectData.FilePath = Path.GetDirectoryName(project.FullName); projectData.AssemblyVersion = project.Properties.Item(Constants.AssemblyVersion)?.Value.ToString(); UnloadProject(solution, projectData.ProjectGuid); DeleteCSProjContents(projectRoot); UpdateCSProjContents(projectRoot, projectData); projectRoot.Save(); UpdateAssemblyInfo(projectData.FilePath); ReloadProject(solution, projectData.ProjectGuid); }
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.UnloadProject(ref guid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); //ErrorHandler.ThrowOnFailure(res); } string message = "Unload 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 static Project ReloadProject(IServiceProvider aServiceProvider, EnvDTE.Project aProject) { IVsSolution4 solution = aServiceProvider.GetService(typeof(SVsSolution)) as IVsSolution4; int err = ((IVsSolution)solution).GetProjectOfUniqueName(aProject.UniqueName, out IVsHierarchy hierarchy); if (VSConstants.S_OK != err) { return(null); } uint itemId = (uint)VSConstants.VSITEMID.Root; err = hierarchy.GetGuidProperty(itemId, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out Guid projectGuid); if (VSConstants.S_OK != err) { return(null); } err = solution.EnsureProjectIsLoaded(projectGuid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None); if (VSConstants.S_OK != err) { return(null); } err = ((IVsSolution)solution).GetProjectOfGuid(projectGuid, out IVsHierarchy loadedProject); if (VSConstants.S_OK != err) { return(null); } loadedProject.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out object objProject); return(objProject as EnvDTE.Project); }
void UnloadProject(IVsSolution4 solution, Guid projectGuid) { ThreadHelper.ThrowIfNotOnUIThread(); int hr; hr = solution.UnloadProject(ref projectGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); ErrorHandler.ThrowOnFailure(hr); }
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); }
async Task ConvertProjectAsync(Project project) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); await DeleteProjectItemAsync(project, "Web.Config"); //await DeleteProjectItemAsync(project, "Web.Debug.config"); //await DeleteProjectItemAsync(project, "Web.Release.config"); await DeleteProjectItemAsync(project, "packages.config"); //await DeleteProjectItemAsync(project, "Global.asax.cs"); await DeleteProjectItemAsync(project, "Global.asax"); await DeleteProjectItemAsync(project, "App_Start"); await DeleteProjectItemAsync(project, "Properties"); await DeleteProjectItemAsync(project, "Views"); //await DeleteProjectItemAsync(project, "RouteConfig.cs"); //await DeleteProjectItemAsync(project, "WebApiConfig.cs"); //var resultAll = prjItems.OfType<ProjectItem>().Select(c => c); //var test1 = resultAll.Where(c => //{ // Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); // return c.Name.ToLower() == "packages.config"; //}) //.FirstOrDefault(); //test1.Remove(); IVsSolution4 solution = await ServiceProvider.GetServiceAsync(typeof(SVsSolution)) as IVsSolution4; ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName); //建立 .NET Core 相關檔案 await CreateProjectItemAsync(project, "startup.cs", projectRoot.PropertyGroups.FirstOrDefault()); await CreateProjectItemAsync(project, "program.cs", projectRoot.PropertyGroups.FirstOrDefault()); await CreateProjectItemAsync(project, "appsettings.json", projectRoot.PropertyGroups.FirstOrDefault()); var projectData = ReadProjectData(projectRoot); projectData.FilePath = Path.GetDirectoryName(project.FullName); projectData.AssemblyVersion = project.Properties.Item(Constants.AssemblyVersion)?.Value.ToString(); UnloadProject(solution, projectData.ProjectGuid); DeleteCSProjContents(projectRoot); UpdateCSProjectFolders(projectRoot); UpdateCSProjContents(projectRoot, projectData); projectRoot.Save(); //UpdateAssemblyInfo(projectData.FilePath); ReloadProject(solution, projectData.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); }
public static bool TryGetIdentifier(this IVsSolution4 solution, IVsHierarchy hierarchy, out Guid identifier) { if (solution is null) { throw new ArgumentNullException(nameof(solution)); } ThreadHelper.ThrowIfNotOnUIThread(); return(ErrorHandler.Succeeded(((IVsSolution)solution).GetGuidOfProject(hierarchy, out identifier))); }
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 string GetName(this IVsSolution4 solution, Guid identifier) { ThreadHelper.ThrowIfNotOnUIThread(); TryGetHierarchy(solution, identifier, out IVsHierarchy hierarchy); if (HierarchyUtilities.TryGetHierarchyProperty(hierarchy, VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_Name, out string name)) { return(name); } return("?"); }
public SolutionManager(IVsSolution solution, IOutputWindow outputWindow) { Dispatcher.CurrentDispatcher.VerifyAccess(); if (solution == null) { throw new ArgumentNullException("solution", "solution is null."); } m_solution = solution; m_solution4 = (IVsSolution4)solution; m_outputWindow = outputWindow; }
private static bool IsLoaded(IVsSolution4 solution, Guid identifier) { ThreadHelper.ThrowIfNotOnUIThread(); if (solution.TryGetHierarchy(identifier, out IVsHierarchy hierarchy)) { return(!HierarchyUtilities.IsStubHierarchy(hierarchy)); } else { return(false); } }
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); }
public SolutionService([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider) { ThreadHelper.ThrowIfNotOnUIThread(); _vsSolution1 = serviceProvider.GetService <SVsSolution, IVsSolution>(); _vsSolution2 = serviceProvider.GetService <SVsSolution, IVsSolution2>(); _vsSolution4 = serviceProvider.GetService <SVsSolution, IVsSolution4>(); _vsImageService2 = serviceProvider.GetService <SVsImageService, IVsImageService2>(); _vsSolution1.AdviseSolutionEvents(this, out _solutionEvents1Cookie); _vsSolution1.AdviseSolutionEvents(this, out _solutionEvents4Cookie); }
public static void UnloadProject(Guid projectGuid) { if (projectGuid == Guid.Empty) { return; } IVsSolution4 solution = _serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution4; int hr; hr = solution.UnloadProject(ref projectGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser); ErrorHandler.ThrowOnFailure(hr); }
private SolutionManager GetSolutionManager() { Dispatcher.CurrentDispatcher.VerifyAccess(); IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution)); IVsSolution4 sol4 = (IVsSolution4)GetService(typeof(SVsSolution)); if (null != solution) { return(new SolutionManager(solution, new OutputWindow(this))); } return(null); }
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)); } }
public State(IWaitDialog waitDialog, ThreadedWaitDialogProgressData initialProgress, IVsSolution4 solution) { _waitDialog = waitDialog; _currentProgress = initialProgress; Solution = solution; _projectsToLoad = new HashSet <Guid>(); _loadedProjects = new HashSet <Guid>(); _projectsToUnload = new HashSet <Guid>(); _unloadedProjects = new HashSet <Guid>(); ProjectsVisitedWhileLoading = new HashSet <Guid>(); RequiresProjectDependencyCalculation = true; }
/// <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); }
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 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); } }
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"); }); }
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); }
public SolutionWrapper( IVsSolution solution, IVsSolution2 solution2 = null, IVsSolution3 solution3 = null, IVsSolution4 solution4 = null, IVsSolution5 solution5 = null, IVsSolution6 solution6 = null, IVsSolution7 solution7 = null, IVsSolution8 solution8 = null ) { _solution = solution; _solution2 = solution2; _solution3 = solution3; _solution4 = solution4; _solution5 = solution5; _solution6 = solution6; _solution7 = solution7; _solution8 = solution8; }
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); } }