Esempio n. 1
0
        public static void LoadProject(DTE dte, string projectName)
        {
            IVsSolution4 solution4 = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution4;

            // Set Current Directory
            Directory.SetCurrentDirectory(dte.Solution.FileName.Remove(dte.Solution.FileName.LastIndexOf('\\')));

            // Load Solution and get Project Names & Guids
            projects = FileParser.GetProjects(dte.Solution.FileName);

            // Read All Project Content
            foreach (CsProject project in projects.Values)
            {
                // Project Exists? If not, skip it
                if (!File.Exists(project.Path))
                {
                    continue;
                }

                // Read Xml
                project.Data = File.ReadAllText(project.Path);

                // Parse Xml
                project.XmlDocument = new System.Xml.XmlDocument();
                project.XmlDocument.LoadXml(project.Data);
            }

            // Init ProjectGuids
            projectGuids = new List <Guid>();

            // Load Project
            LoadProject(solution4, projectName);

            // Ensure projects are loaded (NOT sure this does anything)
            solution4.EnsureProjectsAreLoaded((uint)projectGuids.Count, projectGuids.ToArray(), 10);

            // Clear ProjectGuids
            projectGuids = null;
        }
Esempio n. 2
0
        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);
                }
            }
        }