Example #1
0
        /// <summary>
        /// Provide UI to add a JAR reference.
        /// </summary>
        private void AddJarReference()
        {
            // Get the current project
            var project = (IVsHierarchy)GetCurrentProject();

            using (var dialog = new AddJarReferenceDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var jarPath    = dialog.JarPath;
                    var libName    = dialog.LibraryName;
                    var importCode = dialog.ImportCode;

                    var item = BuildProject.AddItem("JarReference", jarPath).Single();
                    if (!string.IsNullOrEmpty(libName))
                    {
                        item.SetMetadataValue("LibraryName", libName);
                    }
                    if (importCode)
                    {
                        item.SetMetadataValue("ImportCode", "yes");
                    }

                    // Save project
                    BuildProject.Save();

                    // Unload the project - also saves the modifications
                    ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, project, 0));

                    // Reload project
                    dte.ExecuteCommand("Project.ReloadProject", "");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Make sure deleting a project clears the error list
        /// </summary>
        public void ErrorListAndTaskListAreClearedWhenProjectIsUnloaded(VisualStudioApp app)
        {
            var project     = app.OpenProject(app.CopyProjectForTest(@"TestData\ErrorProjectDelete.sln"));
            var projectNode = project.GetPythonProject();

            app.OpenDocument(Path.Combine(projectNode.ProjectHome, "Program.py"));

            app.OpenErrorList();
            //app.OpenTaskList();

            app.WaitForTaskListItems(typeof(SVsErrorList), 7);
            //app.WaitForTaskListItems(typeof(SVsTaskList), 2);

            IVsSolution solutionService = app.GetService <IVsSolution>(typeof(SVsSolution));

            Assert.IsNotNull(solutionService);

            IVsHierarchy selectedHierarchy;

            ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy));
            Assert.IsNotNull(selectedHierarchy);

            Console.WriteLine("Unloading project");
            ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0));

            app.WaitForTaskListItems(typeof(SVsErrorList), 0);
            //app.WaitForTaskListItems(typeof(SVsTaskList), 0);
        }
 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);
     }
 }
Example #4
0
        public static void CloseCurrentSolution()
        {
            IVsSolution solutionService = (IVsSolution)VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsSolution));
            int         ret             = solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave, null, 0);

            Assert.AreEqual(VSConstants.S_OK, ret);
        }
        internal void ReloadProject(int n)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            DTE dte = (DTE)VsIdeTestHostContext.ServiceProvider.GetService(typeof(DTE));

            Project proj = dte.Solution.Projects.Item(1);

            string uniqueName = proj.UniqueName;
            string name       = proj.Name;

            IVsSolution solutionService = (IVsSolution)VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsSolution));

            IVsHierarchy hier;

            Marshal.ThrowExceptionForHR(solutionService.GetProjectOfUniqueName(uniqueName, out hier));

            solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0);

            Window solutionExplorer = dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer) as Window;

            solutionExplorer.Activate();
            UIHierarchy uiHier = solutionExplorer.Object as UIHierarchy;

            UIHierarchyItem item = uiHier.GetItem(Path.GetFileNameWithoutExtension(dte.Solution.FileName) + "\\" + name);

            item.Select(vsUISelectionType.vsUISelectionTypeSelect);

            dte.ExecuteCommand("Project.ReloadProject", "");
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fullFileName"></param>
        public static void CloseInEditorWithoutSaving(IServiceProvider serviceProvider, string fullFileName)
        {
            #region Input validation
            Debug.Assert(serviceProvider != null, "ServiceProvider cannot be null");
            Debug.Assert(fullFileName != null && fullFileName.Length > 0, "fullFileName cannot be empty");
            #endregion

            // Get the RDT service
            IVsRunningDocumentTable runningDocumentTableService = (IVsRunningDocumentTable)serviceProvider.GetService(typeof(IVsRunningDocumentTable));
            Debug.Assert(runningDocumentTableService != null, "Failed to get the Running Document Table Service");

            // Get our document cookie and hierarchy for the file
            uint         docCookie;
            IntPtr       docData;
            IVsHierarchy hierarchy;
            uint         itemId;
            runningDocumentTableService.FindAndLockDocument(
                (uint)Microsoft.VisualStudio.Shell.Interop._VSRDTFLAGS.RDT_NoLock,
                fullFileName,
                out hierarchy,
                out itemId,
                out docData,
                out docCookie);

            // Get the SolutionService
            IVsSolution solutionService = serviceProvider.GetService(typeof(IVsSolution)) as IVsSolution;
            Debug.Assert(solutionService != null, "Failed to get IVsSolution service");

            // Close the document
            solutionService.CloseSolutionElement(
                (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave,
                hierarchy,
                docCookie);
        }
Example #7
0
 public void RemoveProject(string projectPath, IVsHierarchy project)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     _packageHelper.LogInfo($"Removing reference project: {projectPath}");
     _solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_DeleteProject, project, 0);
     _packageHelper.LogInfo($"Removed reference project: {projectPath}");
 }
Example #8
0
        public void TestProjectWithErrorsUnloadProject()
        {
            var project = DebugProject.OpenProject(@"Python.VS.TestData\ErrorProjectDelete.sln");
            var app     = new PythonVisualStudioApp(VsIdeTestHostContext.Dte);

            var errorList = (IVsErrorList)VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsErrorList));

            const int          expectedItems = 2;
            List <IVsTaskItem> allItems      = GetErrorListItems(errorList, expectedItems);

            Assert.AreEqual(expectedItems, allItems.Count);

            IVsSolution solutionService = VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsSolution)) as IVsSolution;

            Debug.Assert(solutionService != null);

            IVsHierarchy selectedHierarchy;

            ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy));
            Debug.Assert(selectedHierarchy != null);

            ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0));

            allItems = GetErrorListItems(errorList, 0);
            Assert.AreEqual(0, allItems.Count);
        }
Example #9
0
        public void CloseInEditorWithoutSaving(string fullFileName)
        {
            // Get the RDT service
            IVsRunningDocumentTable runningDocumentTableService = (IVsRunningDocumentTable)VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsRunningDocumentTable));

            Assert.IsNotNull(runningDocumentTableService, "Failed to get the Running Document Table Service");

            // Get our document cookie and hierarchy for the file
            uint         docCookie;
            IntPtr       docData;
            IVsHierarchy hierarchy;
            uint         itemId;

            runningDocumentTableService.FindAndLockDocument(
                (uint)Microsoft.VisualStudio.Shell.Interop._VSRDTFLAGS.RDT_NoLock,
                fullFileName,
                out hierarchy,
                out itemId,
                out docData,
                out docCookie);

            // Get the SolutionService
            IVsSolution solutionService = VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsSolution)) as IVsSolution;

            Assert.IsNotNull(solutionService, "Failed to get IVsSolution service");

            // Close the document
            solutionService.CloseSolutionElement(
                (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave,
                hierarchy,
                docCookie);
        }
Example #10
0
        public void CloseCurrentSolution(__VSSLNSAVEOPTIONS saveoptions)
        {
            // Get solution service
            IVsSolution solutionService = (IVsSolution)VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsSolution));

            // Close already open solution
            solutionService.CloseSolutionElement((uint)saveoptions, null, 0);
        }
        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);
        }
Example #12
0
        /// <summary>
        /// Closes the currently open solution
        /// </summary>
        public static IVsSolution CloseCurrentSolution(IServiceProvider serviceProvider)
        {
            // Get solution service
            IVsSolution solutionService = (IVsSolution)serviceProvider.GetService(typeof(IVsSolution));

            // Close already open solution
            solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave, null, 0);

            return(solutionService);
        }
Example #13
0
        public async Task <int> ReloadSolutionAsync(CancellationToken cancellationToken)
        {
            if (_isSolutionReloading == 1 || Interlocked.Increment(ref _isSolutionReloading) != 1)
            {
                return(0);
            }

            try
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                IVsSolution solution = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution;

                Assumes.Present(solution);

                List <IVsProject> projects = solution.GetProjects().ToList();

                if (projects.Count != 1)
                {
                    return(0);
                }

                string project = projects.Select(i => i.GetFullPath()).FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));

                int result = solution.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave, null, 0);

                ErrorHandler.ThrowOnFailure(result);

                result = await RunSlnGenAsync(project, cancellationToken);

                ErrorHandler.ThrowOnFailure(result);

                result = solution.OpenSolutionFile((uint)__VSSLNOPENOPTIONS.SLNOPENOPT_Silent, Path.ChangeExtension(project, "sln"));

                ErrorHandler.ThrowOnFailure(result);

                if (SolutionCookie == default)
                {
                    _solutionEvents ??= new SolutionEvents(this);

                    result = solution.AdviseSolutionEvents(_solutionEvents, out uint cookie);

                    ErrorHandler.ThrowOnFailure(result);

                    SolutionCookie = cookie;
                }

                return(result);
            }
            finally
            {
                Interlocked.Decrement(ref _isSolutionReloading);
            }
        }
Example #14
0
        /// <summary>
        /// 关闭一个已经打开的文档
        /// </summary>
        /// <param name="name">文档路径(包含文件后缀)</param>
        /// <param name="saveOption">制定如何关闭一个文档,默认为强制保存后关闭</param>
        public static void CloseDocument(string name, __VSSLNSAVEOPTIONS saveOption = __VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave)
        {
            IVsRunningDocumentTable runningTabs = RunningDocumentTableObject;
            IVsSolution             solution    = VSSolution.SolutionObject;

            if (runningTabs != null)
            {
                IEnumRunningDocuments runningDocuments;
                runningTabs.GetRunningDocumentsEnum(out runningDocuments);

                IntPtr documentData = IntPtr.Zero;
                uint[] docCookie    = new uint[1];
                uint   fetched;

                //遍历所有已经打开的文档
                while ((VSConstants.S_OK == runningDocuments.Next(1, docCookie, out fetched)) && (fetched == 1))
                {
                    uint         flags;
                    uint         editLocks;
                    uint         readLocks;
                    string       filePath;
                    IVsHierarchy docHierarchy;
                    uint         docId;
                    IntPtr       docData = IntPtr.Zero;

                    try
                    {
                        ErrorHandler.ThrowOnFailure(runningTabs.GetDocumentInfo(docCookie[0], out flags, out readLocks,
                                                                                out editLocks, out filePath, out docHierarchy,
                                                                                out docId, out docData));

                        if (solution != null && !filePath.EndsWith("sln") && !filePath.EndsWith("csproj"))
                        {
                            //string currentName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                            if (name == filePath)
                            {
                                solution.CloseSolutionElement((uint)saveOption, docHierarchy, docCookie[0]);
                            }
                        }
                    }
                    finally
                    {
                        if (docData != IntPtr.Zero)
                        {
                            Marshal.Release(docData);
                        }
                    }
                }
            }
        }
Example #15
0
        public void MyTestCleanup()
        {
            IVsSolution solutionService = VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsSolution)) as IVsSolution;

            if (solutionService != null)
            {
                object isOpen;
                solutionService.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out isOpen);
                if ((bool)isOpen)
                {
                    solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, null, 0);
                }
            }
        }
Example #16
0
        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);
        }
Example #17
0
        public void TestRenameOfProjectFile()
        {
            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);

                string extension = Path.GetExtension(project.ProjectFile);
                #region test for bad filenames
                this.TestBadFileNameForSetEditLabel(project);
                #endregion

                string oldUrl       = project.Url;
                string goodFileName = "test";

                project.SetEditLabel(goodFileName);
                Assert.IsTrue(NativeMethods.IsSamePath(project.Url, Path.Combine(project.ProjectFolder, goodFileName + ".nestedProj")), "SetEditLabel failed since the Url test failed");

                Assert.IsTrue((String.Compare(project.ProjectFile, "test" + extension, StringComparison.Ordinal) == 0), "SetEditLabel failed since the file comparison test failed. Expected that " + project.ProjectFile + " equals test.nestedProj");

                // Now do a case only change
                project.SetEditLabel("Test");
                Assert.IsTrue((String.Compare(project.ProjectFile, "Test" + extension, StringComparison.Ordinal) == 0), "SetEditLabel failed since the file comparison test failed. Expected that " + project.ProjectFile + " equals Test.nestedProj");


                this.TestFileNameThatHasToPassForSetEditLabel(project);

                // Now close the project and reopen with the renamed file.
                string projectFullPath      = project.Url;
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                // Close already open solution
                solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, null, 0);

                EnvDTE.Project newProject = dte.Solution.AddFromFile(projectFullPath, true);

                Assert.IsTrue(newProject != null, "failed to load the renamed project");
            });
        }
Example #18
0
        public void TestLoadingOfProjectWithDuplicateItems()
        {
            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);

                string path = project.GetMkDocument();

                // It would be nice if we could just copy the embedded resource to the opened project file, but implicit reload of nested projects crashes on non SP1 versions.
                // For now we are going to close the project and reopen it with the embedded project.
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));

                solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, project, 0);

                TestUtils.WriteEmbeddedResourceToBinaryFile(typeof(TestProject).Assembly, EmbeddedResourceProjectLocation, path);

                IntPtr projectPtr = IntPtr.Zero;
                Guid guid         = Guid.Empty;
                Guid iid          = new Guid("{00000000-0000-0000-C000-000000000046}");        // IID_IUnknown;

                try
                {
                    ErrorHandler.ThrowOnFailure(solutionService.CreateProject(ref guid, path, null, null, (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, ref iid, out projectPtr));

                    // Now see that we have only unique items. We do not care much about canonicalization issues in this test.
                    this.CheckForUniqueCaptions(project);
                }
                finally
                {
                    if (projectPtr != IntPtr.Zero)
                    {
                        Marshal.Release(projectPtr);
                    }
                }
            });
        }
Example #19
0
        public void UnLoadProject()
        {
            Project selectedProject = null;

            if (DTE2.SelectedItems.Count > 0)
            {
                selectedProject = DTE2.SelectedItems.Item(1).Project;
            }
            if (selectedProject != null)
            {
                IVsSolution solutionService = GetService(typeof(SVsSolution)) as IVsSolution;

                Debug.Assert(solutionService != null, "solutionService is null");

                IVsHierarchy selectedHierarchy;
                ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(selectedProject.UniqueName, out selectedHierarchy));
                Debug.Assert(selectedHierarchy != null, "selectedHierarchy is null");

                ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0));
            }
        }
        private void Check_Reopen()
        {
            //Check order 3 (Reopen project - check changes have been saved correctly)
            IVsSolution  sln = (ctx.Properties["solution"] as IVsSolution);
            IVsHierarchy hier;

            sln.OpenSolutionFile(
                (uint)__VSSLNOPENOPTIONS.SLNOPENOPT_Silent, ctx.Properties["slnfile"].ToString());
            sln.GetProjectOfUniqueName(ctx.Properties["testfile"].ToString(), out hier);
            IProjectManager project = (IProjectManager)hier;
            int             i       = 0;

            foreach (var item in project.BuildManager.GetElements(n => n.Name == "Compile"))
            {
                Assert.AreEqual(item.ToString(), fileList[i],
                                "Test {0} after reopen : Compilation order is wrong at {1} position", name, i);
                i++;
            }

            sln.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_SLNSAVEOPT_MASK, null, 0);
        }
 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);
     }
 }
Example #22
0
        public void ErrorListAndTaskListAreClearedWhenProjectIsUnloaded()
        {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ErrorProjectDelete.sln");

                app.WaitForTaskListItems(typeof(SVsErrorList), 7);
                app.WaitForTaskListItems(typeof(SVsTaskList), 2);

                IVsSolution solutionService = app.GetService <IVsSolution>(typeof(SVsSolution));
                Assert.IsNotNull(solutionService);

                IVsHierarchy selectedHierarchy;
                ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy));
                Assert.IsNotNull(selectedHierarchy);

                Console.WriteLine("Unloading project");
                ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0));

                app.WaitForTaskListItems(typeof(SVsErrorList), 0);
                app.WaitForTaskListItems(typeof(SVsTaskList), 0);
            }
        }
Example #23
0
        public void TestSaveAsOnProjectFile()
        {
            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);

                MethodInfo saveAs = project.GetType().GetMethod("SaveAs", BindingFlags.Instance | BindingFlags.NonPublic);

                #region test for bad filenames
                this.TestBadFileNameForSaveAs(sp, project, saveAs);
                #endregion

                string oldUrl       = project.Url;
                string goodFileName = project.ProjectFolder + "\\test.nestedproj";
                saveAs.Invoke(project, new object[] { goodFileName });

                Assert.IsTrue(NativeMethods.IsSamePath(project.Url, goodFileName), "Save as failed since the Url test failed");
                Assert.IsTrue((String.Compare(project.ProjectFile, "test.nestedProj", StringComparison.OrdinalIgnoreCase) == 0), "Save as failed since the file comparison test failed");

                this.TestFileNameThatHasToPassForSaveAs(project, saveAs);

                // Now close the project and reopen with the renamed file.
                string projectFullPath      = project.Url;
                IVsSolution solutionService = (IVsSolution)sp.GetService(typeof(IVsSolution));
                // Close already open solution
                solutionService.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_SaveIfDirty, null, 0);

                EnvDTE.Project newProject = dte.Solution.AddFromFile(projectFullPath, true);

                Assert.IsTrue(newProject != null, "failed to load the renamed project");
            });
        }
Example #24
0
        /// <summary>
        /// Reloads a nested project node by deleting it and readding it.
        /// </summary>
        /// <param name="node">The node to reload.</param>
        protected virtual void ReloadNestedProjectNode(NestedProjectNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            IVsSolution solution = this.GetService(typeof(IVsSolution)) as IVsSolution;

            if (solution == null)
            {
                throw new InvalidOperationException();
            }

            NestedProjectNode newNode = null;

            try
            {
                // (VS 2005 UPDATE) When deleting and re-adding the nested project,
                // we do not want SCC to see this as a delete and add operation.
                this.EventTriggeringFlag = ProjectNode.EventTriggering.DoNotTriggerTrackerEvents;

                // notify SolutionEvents listeners that we are about to add children
                IVsFireSolutionEvents fireSolutionEvents = solution as IVsFireSolutionEvents;

                if (fireSolutionEvents == null)
                {
                    throw new InvalidOperationException();
                }

                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnBeforeUnloadProject(node.NestedHierarchy));

                int isDirtyAsInt = 0;
                this.IsDirty(out isDirtyAsInt);

                bool isDirty = (isDirtyAsInt == 0) ? false : true;

                ProjectElement element = node.ItemNode;
                node.CloseNestedProjectNode();

                // Remove from the solution
                this.RemoveChild(node);

                // Now readd it
                try
                {
                    __VSCREATEPROJFLAGS flags = __VSCREATEPROJFLAGS.CPF_NOTINSLNEXPLR | __VSCREATEPROJFLAGS.CPF_SILENT | __VSCREATEPROJFLAGS.CPF_OPENFILE;
                    newNode = this.AddExistingNestedProject(element, flags);
                    newNode.AddVirtualProject();
                }
                catch (Exception e)
                {
                    // We get a System.Exception if anything failed, thus we have no choice but catch it.
                    // Exceptions are digested by VS. Show the error if not in automation.
                    if (!Utilities.IsInAutomationFunction(this.Site))
                    {
                        string          message       = (String.IsNullOrEmpty(e.Message)) ? SR.GetString(SR.NestedProjectFailedToReload, CultureInfo.CurrentUICulture) : e.Message;
                        string          title         = string.Empty;
                        OLEMSGICON      icon          = OLEMSGICON.OLEMSGICON_CRITICAL;
                        OLEMSGBUTTON    buttons       = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                        OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                        VsShellUtilities.ShowMessageBox(this.Site, title, message, icon, buttons, defaultButton);
                    }

                    // Do not digest exception. let the caller handle it. If in a later stage this exception is not digested then the above messagebox is not needed.
                    throw;
                }

#if DEBUG
                IVsHierarchy nestedHierarchy;
                ErrorHandler.ThrowOnFailure(solution.GetProjectOfUniqueName(newNode.GetMkDocument(), out nestedHierarchy));
                Debug.Assert(nestedHierarchy != null && Utilities.IsSameComObject(nestedHierarchy, newNode.NestedHierarchy), "The nested hierrachy was not reloaded correctly.");
#endif
                this.SetProjectFileDirty(isDirty);

                ErrorHandler.ThrowOnFailure(fireSolutionEvents.FireOnAfterLoadProject(newNode.NestedHierarchy));
            }
            finally
            {
                // In this scenario the nested project failed to unload or reload the nested project. We will unload the whole project, otherwise the nested project is lost.
                // This is similar to the scenario when one wants to open a project and the nested project cannot be loaded because for example the project file has xml errors.
                // We should note that we rely here that if the unload fails then exceptions are not digested and are shown to the user.
                if (newNode == null || newNode.NestedHierarchy == null)
                {
                    ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject | (uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_ForceSave, this, 0));
                }
                else
                {
                    this.EventTriggeringFlag = ProjectNode.EventTriggering.TriggerAll;
                }
            }
        }
Example #25
0
        // Get Revision button click
        private void newOKBtn_Click(object sender, EventArgs e)
        {
            bool        updateSolution = false;
            IVsSolution solution       = null;
            string      path           = _scm.SolutionFile;

            IList <IVsHierarchy> projectsUpdating    = new List <IVsHierarchy>();
            IList <string>       projectsClosed      = new List <string>();
            IList <Guid>         projectsGuidsClosed = new List <Guid>();

            if (_isSolutionIncluded)
            {
                // Figure out a better test

                //updateSolution = _scm.SyncFile(
                //    new P4.SyncFilesCmdOptions(P4.SyncFilesCmdFlags.Preview, 1),
                //    path);

                updateSolution = true;
            }
            if (updateSolution)
            {
                if (DialogResult.Cancel == MessageBox.Show(
                        Resources.GetRevisionDlg_UpdatingSlnWarninig,
                        Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                {
                    return;
                }
                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));

                P4VsProvider.Instance.SuppressConnection = true;

                if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                {
                    MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (P4VsProvider.Instance.SccService.SelectedNodes != null)
            {
                bool needToAsk = true;
                foreach (VSITEMSELECTION pItem in P4VsProvider.Instance.SccService.SelectedNodes)
                {
                    if ((pItem.itemid == VSConstants.VSITEMID_ROOT) && (P4VsProvider.Instance.SccService.IsProjectControlled(pItem.pHier)))
                    {
#if VS2008
                        if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                   Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                        {
                            return;
                        }
                        updateSolution = true;

                        solution = (IVsSolution)GetService(typeof(SVsSolution));

                        P4VsProvider.Instance.SuppressConnection = true;

                        if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, null, 0))
                        {
                            MessageBox.Show(Resources.Error_ClosingSolution, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;
#else
                        IVsProject3 pProj = pItem.pHier as IVsProject3;
                        if (pProj != null)
                        {
                            if (needToAsk == true)
                            {
                                if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_UpdatingProjWarninig,
                                                                           Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                                {
                                    return;
                                }
                                needToAsk = false;
                            }
                            projectsUpdating.Add(pItem.pHier);

                            if (solution == null)
                            {
                                solution = (IVsSolution)P4VsProvider.Instance.GetService(typeof(SVsSolution));
                            }
                            Guid projGuid;
                            solution.GetGuidOfProject(pItem.pHier, out projGuid);
                            projectsGuidsClosed.Add(projGuid);

                            if (VSConstants.S_OK != solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, pItem.pHier, 0))
                            {
                                MessageBox.Show(Resources.Error_ClosingProject, Resources.P4VS, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
#endif
                    }
                }
            }
            List <string> refreshItems = new List <string>();

            try
            {
                //change this to a better global validator
                int  test = 0;
                bool num  = int.TryParse(ValueTB.Text, out test);
                if (specifierRB.Checked == true &&
                    num == false &&
                    specifierCB.SelectedIndex == 0 &&
                    ValueTB.Text != "head" &&
                    ValueTB.Text != "have" &&
                    ValueTB.Text != "none"
                    )
                {
                    MessageBox.Show(string.Format(Resources.GetRevisionDlg_InvalidRevisionSpecifierWarninig, ValueTB.Text));
                    ValueTB.Text = string.Empty;
                    return;
                }
                ////////
                _files = new List <P4.FileSpec>();

                foreach (ListViewItem item in filesListView.Items)
                {
                    P4.FileSpec     file = new P4.FileSpec();
                    P4.FileMetaData fmd  = new P4.FileMetaData();
                    if (item.Text.EndsWith("/..."))
                    {
                        fmd.DepotPath = new P4.DepotPath(item.Text);
                    }
                    else
                    {
                        fmd = _scm.GetFileMetaData(item.Text);
                    }

                    if (fmd.LocalPath != null)
                    {
                        file.LocalPath = fmd.LocalPath;
                    }
                    if (fmd.ClientPath != null)
                    {
                        file.ClientPath = fmd.ClientPath;
                    }
                    if (fmd.DepotPath != null)
                    {
                        file.DepotPath = fmd.DepotPath;
                    }
                    _files.Add(file);
                    refreshItems.Add(item.Text.ToString());
                }

                P4.SyncFilesCmdFlags flags = new P4.SyncFilesCmdFlags();
                flags = P4.SyncFilesCmdFlags.None;
                if (forceChk.Checked == true)
                {
                    flags = P4.SyncFilesCmdFlags.Force;
                }

                P4.Options options = new P4.Options(flags, -1);

                // set up the list of paths with specifiers that we will sync to
                IList <P4.FileSpec> files = new List <P4.FileSpec>();
                //int idx = 0;

                if (specifierRB.Checked == true)
                {
                    // #revision
                    if (specifierCB.SelectedIndex == 0)
                    {
                        bool disconnectAfterSync = false;
                        int  number = 0;
                        bool isnum  = int.TryParse(Value, out number);
                        if (isnum == true)
                        {
                            if (number == 0)
                            {
                                if (_isSolutionIncluded)
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingSlnWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                    disconnectAfterSync = true;
                                }
                                else
                                {
                                    if (DialogResult.Cancel == MessageBox.Show(Resources.GetRevisionDlg_RemovingProjWarninig,
                                                                               Resources.P4VS, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                                    {
                                        this.DialogResult = DialogResult.Cancel;
                                        return;
                                    }
                                }
                            }
                        }
                        foreach (P4.FileSpec file in _files)
                        {
                            if (isnum == true)
                            {
                                // skip meta data check for rev 0 there is none, but we dtill want to allow
                                // this as a way to remove the local copy of the file, but still keep checking
                                // to make sure other bad revisions are not fetched such as file that was moved
                                if (number != 0)
                                {
                                    IList <P4.FileSpec> fs = new List <FileSpec>();
                                    file.Version = new P4.Revision(number);
                                    fs.Add(file);
                                    IList <P4.FileMetaData> fmd = _scm.GetFileMetaData(fs, null);
                                    if (fmd == null)
                                    {
                                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                                        {
                                            if (_files.Count == 1)
                                            {
                                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                            }
                                            P4VsOutputWindow.AppendMessage(_scm.Connection.Repository.Connection.LastResults.ErrorList[0].ToString());
                                        }
                                        continue;
                                    }
                                }
                                file.Version = new P4.Revision(number);
                            }
                            else if (Value == "head")
                            {
                                file.Version = new P4.HeadRevision();
                            }
                            else if (Value == "have")
                            {
                                file.Version = new P4.HaveRevision();
                            }
                            else if (Value == "none")
                            {
                                file.Version = new P4.NoneRevision();
                            }
                            files.Add(file);
                        }
                        if (files.Count > 0)
                        {
                            _scm.SyncFiles(options, files);
                        }
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            if (_scm.SccService == null)
                            {
                                return;
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        if (disconnectAfterSync)
                        {
                            P4VsProvider.Instance.SccService.Dispose();
                        }
                    }

                    // @workspace
                    if (specifierCB.SelectedIndex == 4)
                    {
                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.ClientNameVersion(Value.ToString());
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @date/time
                    if (specifierCB.SelectedIndex == 2)
                    {
                        DateTime value = dateTimePicker.Value;

                        string timestamp = value.Date.ToShortDateString() + ":" + value.TimeOfDay.ToString();

                        foreach (P4.FileSpec file in _files)
                        {
                            file.Version = new P4.DateTimeVersion(value);
                            files.Add(file);
                        }
                        _scm.SyncFiles(options, _files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @changelist
                    if (specifierCB.SelectedIndex == 1)
                    {
                        if (changelistFilesChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.ChangelistIdVersion(Convert.ToInt16(Value)),
                                                                   new P4.ChangelistIdVersion(Convert.ToInt32(Value)));
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.ChangelistIdVersion(Convert.ToInt32(Value));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }

                    // @label
                    if (specifierCB.SelectedIndex == 3)
                    {
                        if (removeChk.Checked == true)
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.LabelNameVersion(Value.ToString());
                                files.Add(file);
                            }
                        }
                        else
                        {
                            foreach (P4.FileSpec file in _files)
                            {
                                file.Version = new P4.VersionRange(new P4.LabelNameVersion(Value.ToString()),
                                                                   new P4.LabelNameVersion(Value.ToString()));
                                files.Add(file);
                            }
                        }
                        _scm.SyncFiles(options, files);
                        if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                        {
                            IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                            foreach (P4.P4ClientError error in errors)
                            {
                                if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                    error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                                {
                                    P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                    return;
                                }
                            }
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                }

                else if (getLatestRB.Checked == true)
                {
                    files = _files;
                    _scm.SyncFiles(options, files);
                    if (_scm.Connection.Repository.Connection.LastResults.ErrorList != null)
                    {
                        IList <P4.P4ClientError> errors = _scm.Connection.Repository.Connection.LastResults.ErrorList.ToList();
                        foreach (P4.P4ClientError error in errors)
                        {
                            if (error.SeverityLevel == P4.ErrorSeverity.E_FAILED |
                                error.SeverityLevel == P4.ErrorSeverity.E_FATAL)
                            {
                                P4ErrorDlg.Show(_scm.Connection.Repository.Connection.LastResults, false);
                                return;
                            }
                        }
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            finally
            {
                if (updateSolution)
                {
                    if (path != null)
                    {
                        solution.OpenSolutionFile(0, path);
                    }
                    if (_scm.SccService != null)
                    {
                        _scm.SccService.ResetSelection();
                    }
                }
#if !VS2008
                else if (projectsUpdating.Count > 0)
                {
                    foreach (Guid projGuid in projectsGuidsClosed)
                    {
                        Guid rProjGuid = projGuid;

                        var vsSolution4 = (IVsSolution4)solution;
                        if (vsSolution4 != null)
                        {
                            int res = vsSolution4.ReloadProject(ref rProjGuid);
                        }
                    }
                }
#endif
                // now refresh the selected nodes' glyphs
                if (_scm.SccService != null)
                {
                    _scm.SccService.UpdateProjectGlyphs(refreshItems, true);
                }
            }
        }
Example #26
0
 private void CloseSolution()
 {
     sln.CloseSolutionElement
         ((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_SLNSAVEOPT_MASK, null, 0);
 }
Example #27
0
 public int CloseSolutionElement(uint grfCloseOpts, IVsHierarchy pHier, uint docCookie)
 {
     return(_solution.CloseSolutionElement(grfCloseOpts, pHier, docCookie));
 }
        public void RunFinished()
        {

            sln = ((IVsSolution)Package.GetGlobalService(typeof(SVsSolution)));
            ServiceProvider serviceProvider = new ServiceProvider(dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
            string projectGuid = null;
            using (XmlReader projectReader = XmlReader.Create(fileName))
            {
                projectReader.MoveToContent();
                object nodeName = projectReader.NameTable.Add("ProjectGuid");
                while (projectReader.Read())
                {
                    if (Object.Equals(projectReader.LocalName, nodeName))
                    {
                        projectGuid = projectReader.ReadElementContentAsString();
                        break;
                    }
                }
            }
            IVsHierarchy hier = VsShellUtilities.GetHierarchy(serviceProvider, new Guid(projectGuid));
            sln.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0);
            String bistroPath = (String)Registry.LocalMachine.CreateSubKey(@"Software\Hill30\Bistro").GetValue("InstallDir");
#if VS2008
            String ndjangoPath = (String)Registry.LocalMachine.CreateSubKey(@"Software\Hill30\NDjango").GetValue("InstallDir2008");
#elif VS2010
            String ndjangoPath = (String)Registry.LocalMachine.CreateSubKey(@"Software\Hill30\NDjango").GetValue("InstallDir2010");
#endif
            StreamReader reader = new StreamReader(fileName);
            string content = reader.ReadToEnd();
            reader.Close();
            content = content.Replace(BISTRODIR, (bistroPath == null) ? BISTRODIR : Path.GetFullPath(bistroPath)).
                Replace(NDJANGODIR, (ndjangoPath == null) ? NDJANGODIR : Path.GetFullPath(ndjangoPath));
            StreamWriter sw = new StreamWriter(fileName);
            sw.Write(content);
            sw.Close();
            IntPtr ppProject = IntPtr.Zero;
            Guid guid1 = new Guid();
            Guid guid2 = new Guid();
            sln.CreateProject(ref guid1, fileName, null, null, (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, ref guid2, out ppProject);


        }