Exemple #1
0
        /// <summary>
        /// Finds a solution folder in the solution hierarchy, given its
        /// folder-like location path.
        /// </summary>
        /// <returns>The solution folder or <see langword="null" /> if
        /// it doesn't exist.</returns>
        /// <remarks>
        /// Note that this method performs the same work as <see cref="FindProjectByPath"/>,
        /// but only returns an instance if the Project.Object is actually
        /// an <see cref="EnvDTE80.SolutionFolder"/>. This is because solution folders
        /// are represented as <see cref="Project"/> elements in Visual Studio.
        /// </remarks>
        public static EnvDTE80.SolutionFolder FindSolutionFolderByPath(EnvDTE.Solution root, string path)
        {
            Guard.ArgumentNotNull(root, "root");
            Guard.ArgumentNotNull(path, "path");
            Project prj = FindProjectByPath(root, path);

            if (prj != null)
            {
                return(prj.Object as EnvDTE80.SolutionFolder);
            }
            return(null);
        }
Exemple #2
0
        public void how_to_convert_DTE_Solution_to_ISolutionNode()
        {
            // Say you have a DTE Solution:
            EnvDTE.Solution dteSolution = Dte.Solution;

            ISolutionNode solutionNode = dteSolution.Adapt().AsSolutionNode();

            Assert.IsNotNull(solutionNode);

            // Use the solution node to get the active project, for example:
            IProjectNode activeProject = solutionNode.ActiveProject;
        }
Exemple #3
0
        public static void ClassInitialize(TestContext testContext)
        {
            MessageFilter.Register();
            Type   type = System.Type.GetTypeFromProgID("VisualStudio.DTE.15.0");
            object inst = System.Activator.CreateInstance(type, true);

            dte = (EnvDTE80.DTE2)inst;
            dte.Solution.Open(Path.GetFullPath(@"../../artifacts/tsconfig/Tsconfig.sln"));
            solution = dte.Solution;

            settings = new MockSettings();
        }
Exemple #4
0
        /// <summary>
        /// Finds a project item in the solution hierarchy, given its
        /// folder-like location path.
        /// </summary>
        /// <returns>The project item or <see langword="null" /> if
        /// it doesn't exist.</returns>
        /// <remarks>
        /// Note that even projects and solution folders are represented
        /// as project items, if they are not directly under the solution root,
        /// but this method checks for the ProjectItem.Object property
        /// to discard matches in this case. If the object to retrieve is a
        /// project (or solution folder, which is represented as a project too,
        /// and the folder is retrieved through the Project.Object property),
        /// the <see cref="FindProjectByPath"/> method must be used.
        /// </remarks>
        public static ProjectItem FindItemByPath(EnvDTE.Solution root, string path)
        {
            Guard.ArgumentNotNull(root, "root");
            Guard.ArgumentNotNull(path, "path");

            string[] allpaths = path.Split(
                new char[] {
                System.IO.Path.DirectorySeparatorChar,
                System.IO.Path.AltDirectorySeparatorChar
            },
                StringSplitOptions.RemoveEmptyEntries);

            if (allpaths.Length == 0)
            {
                return(null);
            }

            // First path is the project/solution folder to look into.
            Project prj = null;

            foreach (Project p in root.Projects)
            {
                if (p.Name == allpaths[0])
                {
                    prj = p;
                    break;
                }
            }

            if (prj == null)
            {
                return(null);
            }

            string[] paths = new string[allpaths.Length - 1];
            // If there are no child paths, this is not an item but the project itself.
            if (paths.Length == 0)
            {
                return(null);
            }

            Array.Copy(allpaths, 1, paths, 0, paths.Length);

            ProjectItem item = FindInCollectionRecursive(prj.ProjectItems, paths, 0);

            if ((item != null) && !(item.Object is Project || item.Object is EnvDTE80.SolutionFolder))
            {
                // Only return the item if it's not a container for a Project or SolutionFolder.
                return(item);
            }
            return(null);
        }
Exemple #5
0
        public void CreateTestSolution(string fullyQualifiedPath, string unqualifiedName)
        {
            EnvDTE.Solution soln = System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.Solution")) as EnvDTE.Solution;
            soln.DTE.MainWindow.Visible = true;
            EnvDTE80.Solution2 soln2 = soln as EnvDTE80.Solution2;
            soln2.Create(fullyQualifiedPath, unqualifiedName);
            string csTemplatePath = soln2.GetProjectTemplate("ConsoleApplication.zip", "CSharp");

            soln.AddFromTemplate(csTemplatePath, fullyQualifiedPath, unqualifiedName, false);
            int x = soln.AddIns.Count;

            soln2.SaveAs(fullyQualifiedPath + unqualifiedName + ".sln");
        }
Exemple #6
0
 public bool SaveSolutionQtVersion(EnvDTE.Solution solution, string version)
 {
     if (!IsVersionAvailable(version) && version != "$(DefaultQtVersion)")
     {
         return(false);
     }
     solution.Globals["Qt5Version"] = version;
     if (!solution.Globals.get_VariablePersists("Qt5Version"))
     {
         solution.Globals.set_VariablePersists("Qt5Version", true);
     }
     return(true);
 }
Exemple #7
0
        public static void PutTextToCS(string text)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            EnvDTE.Solution solution  = DTE.Solution;
            EnvDTE.Projects _projects = solution.Projects;

            string s = string.Empty;

            var projects = _projects.GetEnumerator();

            while (projects.MoveNext())
            {
                var items = ((Project)projects.Current).ProjectItems.GetEnumerator();
                while (items.MoveNext())
                {
                    ProjectItem item = (ProjectItem)items.Current;
                    //Recursion to get all ProjectItems
                    s += item.Name + Environment.NewLine;

                    //ExamineItem(item);

                    if (item.Name.EndsWith("cs"))
                    {
                        Window x = item.Open();
                        x.Visible = true;
                        var document = x.Document;
                        document.ReadOnly = false;
                        TextDocument editDoc = document.Object("TextDocument") as TextDocument;

                        string x1 = editDoc.ToString();

                        EditPoint objEditPt = editDoc.CreateEditPoint();
                        editDoc.Selection.Insert(text + Environment.NewLine);
                        System.Windows.Forms.SendKeys.SendWait("^k");
                        System.Windows.Forms.SendKeys.SendWait("^d");
                        //objEditPt.StartOfDocument();
                        //while (!objEditPt.AtEndOfDocument)
                        //{
                        //    //objEditPt.Delete(objEditPt.LineLength);
                        //    objEditPt.LineDown(1);
                        //}
                        //objEditPt.Insert(text);
                        //objEditPt.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsHorizontal);
                        //objEditPt.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical);

                        Console.WriteLine("saving file {0}", document.FullName);
                        //document.Save(document.FullName);
                    }
                }
            }
        }
Exemple #8
0
            static public Report CreateReportFromVsSolution(EnvDTE.Solution dteSolution, Queue <VCProject> vcProjectQueue)
            {
                Report report = new Report();

                //Solution
                Reporting.Solution solution = AddSolution(report, dteSolution);

                foreach (VCProject vcProject in vcProjectQueue)
                {
                    AddProject(solution, vcProject);
                }

                return(report);
            }
 public static void ClassCleanup()
 {
     if (solution != null)
     {
         solution.Close(); solution = null;
     }
     if (dte != null)
     {
         dte.Quit();
     }
     WebLinterVsix.WebLinterPackage.Settings = null;
     WebLinterVsix.WebLinterPackage.Dte      = null;
     MessageFilter.Revoke();
 }
Exemple #10
0
        /// <summary>
        /// Finds a project in the solution hierarchy, given its
        /// folder-like location path. Note that solution folders will
        /// also be returned, as they are represented as <see cref="Project"/> elements
        /// in Visual Studio, and the actual folder can be retrieved by casting
        /// the returned Project.Object property to
        /// <see cref="EnvDTE80.SolutionFolder"/>.
        /// </summary>
        /// <returns>The project or <see langword="null" /> if
        /// it doesn't exist.</returns>
        public static Project FindProjectByPath(EnvDTE.Solution root, string path)
        {
            Guard.ArgumentNotNull(root, "root");
            Guard.ArgumentNotNull(path, "path");

            string[] allpaths = path.Split(System.IO.Path.DirectorySeparatorChar,
                                           System.IO.Path.AltDirectorySeparatorChar);

            if (allpaths.Length == 0)
            {
                return(null);
            }

            // First path is the project/solution folder to look into.
            Project prj = null;

            foreach (Project p in root.Projects)
            {
                if (p.Name == allpaths[0])
                {
                    prj = p;
                    break;
                }
            }

            if (prj == null)
            {
                return(null);
            }

            string[] paths = new string[allpaths.Length - 1];
            // If there are no child paths, we reached the end.
            if (paths.Length == 0)
            {
                return(prj);
            }

            Array.Copy(allpaths, 1, paths, 0, paths.Length);

            ProjectItem item = FindInCollectionRecursive(prj.ProjectItems, paths, 0);

            if (item == null)
            {
                return(null);
            }
            {
                return(item.Object as Project);
            }
        }
Exemple #11
0
        public static bool GetSolutionIsSaved(DTE dte)
        {
            try
            {
                EnvDTE.Solution solution = dte.Solution;

                return(solution.Saved);
            }
            catch (Exception e)
            {
                Logging.Logging.LogError("Exception: " + e.Message);

                throw;
            }
        }
Exemple #12
0
        public static String GetSolutionPath(DTE dte)
        {
            try
            {
                EnvDTE.Solution solution = dte.Solution;

                return(solution.FullName);
            }
            catch (Exception e)
            {
                Logging.Logging.LogError("Exception: " + e.Message);

                return("N/A");
            }
        }
Exemple #13
0
        public string GetSolutionQtVersion(EnvDTE.Solution solution)
        {
            if (solution == null)
            {
                return(null);
            }

            if (solution.Globals.get_VariableExists("Qt5Version"))
            {
                var version = (string)solution.Globals["Qt5Version"];
                return(VerifyIfQtVersionExists(version) ? version : null);
            }

            return(null);
        }
Exemple #14
0
        public static void ClassInitialize(TestContext testContext)
        {
            // This is the official fix for the unused parameter warning IDE0060.  Nice.
            // https://github.com/dotnet/roslyn/issues/35063#issuecomment-484616262
            _ = testContext;
            MessageFilter.Register();
            Type   type = Type.GetTypeFromProgID("VisualStudio.DTE.15.0");
            object inst = Activator.CreateInstance(type, true);

            dte = (EnvDTE80.DTE2)inst;
            dte.Solution.Open(Path.GetFullPath(@"../../artifacts/bad-tslint-json/bad-tslint-json.sln"));
            solution = dte.Solution;

            settings = new MockSettings();
        }
Exemple #15
0
        public static List <Project> GetAllProjectsRecursively(
            this EnvDTE.Solution solution
            )
        {
            var projectList = new List <Project>();

            if (solution.Projects != null)
            {
                foreach (EnvDTE.Project project in solution.Projects)
                {
                    GetSolutionFolderProjects(project, ref projectList);
                }
            }

            return(projectList);
        }
Exemple #16
0
        ///<summary>Gets the directory containing the active solution file.</summary>
        public static string GetSolutionFolderPath()
        {
            EnvDTE.Solution solution = EditProjectPackage.DTE.Solution;

            if (solution == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(solution.FullName))
            {
                return(GetRootFolder());
            }

            return(Path.GetDirectoryName(solution.FullName));
        }
        static private void ReloadAll(DTE dte)
        {
            if (dte == null)
            {
                return;
            }

            EnvDTE.Solution solution = dte.Solution;

            List <EnvDTE.Project> projects = Utility.SolutionUtility.GetSolutionProjectList(dte);

            foreach (EnvDTE.Project project in projects)
            {
                _reloadedProjectGuids.Add(Utility.ProjectUtility.ReloadProject(project));
            }
        }
        private EnvDTE.Solution GetSolution(ClearFilesArgs clearFilesArgs)
        {
            EnvDTE.Solution soln = TryHelper.Run(() => System.Activator.CreateInstance(Type.GetTypeFromProgID(Settings.Default.VisualStudio))) as EnvDTE.Solution;

            TryHelper.Run(() => { soln.DTE.MainWindow.Visible = false; });

            if (!String.IsNullOrWhiteSpace(clearFilesArgs.ProyectFile))
            {
                TryHelper.Run(() => { soln.AddFromFile(clearFilesArgs.ProyectFile); });
            }
            else
            {
                soln.Open(clearFilesArgs.SoluctionFile);
            }

            return(soln);
        }
Exemple #19
0
        /// <summary>
        /// Implementation of IExtenderProvider::GetExtender.
        /// </summary>
        /// <param name="ExtenderCATID">CATID of the object being extended.</param>
        /// <param name="ExtenderName">Name of the Extension.</param>
        /// <param name="ExtendeeObject">Object being extended.</param>
        /// <param name="ExtenderSite">Site object for the Extender.</param>
        /// <param name="cookie">Cookie value that identifies the Extender to its Site.</param>
        /// <returns>A newly created Extender object.</returns>
        public object GetExtender(string ExtenderCATID, string ExtenderName, object ExtendeeObject, EnvDTE.IExtenderSite ExtenderSite, int Cookie)
        {
            object Extender = null;             //In case of failure.

            if (CanExtend(ExtenderCATID, ExtenderName, ExtendeeObject))
            {
                //Note: More complicated implementations can keep a map of Extendees and Extenders
                //they have given out, so that if asked for again for the same Extendee Extender
                //you don't have to recreate it again. In our case, the Extenders are very
                //light-weight objects and have little direct interaction with the Extendee, so
                //we don't bother.

                SolnExtender slnext = new SolnExtender();

                EnvDTE.Solution sln = null;

                //Get the solution automation object.
                //We don't need to interact with the Extendee object much since we go
                //directly to the Solution automation object for our needs, but most
                //implementations would talk directly to the Extendee object to extend/shadow
                //its properties.
                sln = ExtendeeObject as EnvDTE.Solution;
                if (sln == null)
                {
                    //Extending the Soltuion browse object (the object that's displayed
                    //in the property browser when the Solution Node is selected in
                    //the Solution Explorer). In this case, get the DTE.Solution object
                    //directly from the object model.
                    EnvDTE.DTE root = (EnvDTE.DTE)ExtenderSite.GetObject("");
                    sln = root.Solution;
                }

                if (sln != null)
                {
                    //Init our extender.
                    slnext.Init(sln, Cookie, ExtenderSite);
                    Extender = slnext;
                }
            }

            return(Extender);
        }
Exemple #20
0
        public static string GetProjectName(string fileName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            EnvDTE.Solution solution  = DTE.Solution;
            EnvDTE.Projects _projects = solution.Projects;


            string result = null;

            if (DTE != null && DTE.Solution != null)
            {
                ProjectItem prj = DTE.Solution.FindProjectItem(fileName);
                var         x   = prj.ProjectItems;
                if (prj != null)
                {
                    result = prj.ContainingProject.Name;
                }
            }

            return(result);
        }
Exemple #21
0
        public PluginDeployerWindow()
        {
            InitializeComponent();
            DataContext = this;

            _dte = Package.GetGlobalService(typeof(DTE)) as DTE;
            if (_dte == null)
            {
                return;
            }

            _solution = _dte.Solution;
            if (_solution == null)
            {
                return;
            }

            var events       = _dte.Events;
            var windowEvents = events.WindowEvents;

            windowEvents.WindowActivated += WindowEventsOnWindowActivated;
        }
Exemple #22
0
            static public Report CreateReportSingleFile(EnvDTE.Solution dteSolution, VCFile vcFile)
            {
                Report report = new Report();

                //Solution
                Reporting.Solution solution = AddSolution(report, dteSolution);

                //Project
                Reporting.Project project    = solution.CreateProject();
                EnvDTE.Project    dteProject = DTE2Utils.GetProject(vcFile);
                if (dteProject != null)
                {
                    project.Name = dteProject.Name;
                }

                //File
                Reporting.File file = project.CreateFile();
                file.Name     = vcFile.Name;
                file.FullPath = vcFile.FullPath;

                return(report);
            }
        public static IEnumerable <VSProject> GetProjects(this VSSolution solution)
        {
            var projects = new Queue <VSProject>(solution.Projects.Cast <VSProject>());

            while (projects.Count > 0)
            {
                var current = projects.Dequeue();
                if (current.Kind == ProjectKinds.vsProjectKindSolutionFolder)
                {
                    var subProjects = current.ProjectItems.Cast <ProjectItem>()
                                      .Select(c => c.SubProject)
                                      .Where(c => c != null);
                    foreach (var sub in subProjects)
                    {
                        projects.Enqueue(sub);
                    }
                }
                else
                {
                    yield return(current);
                }
            }
        }
Exemple #24
0
        /// <summary>
        /// Iterates all the projects in the solution, irrespective of their depth in the
        /// solution hierarchy of items.
        /// </summary>
        /// <param name="solution">The solution to iterate looking for projects.</param>
        /// <param name="processAndBreak">Delegate to perform processing for each project found.
        /// The return value signals whether further iteration should continue or not.</param>
        public static void ForEachProject(EnvDTE.Solution solution, Predicate <Project> processAndBreak)
        {
            Guard.ArgumentNotNull(solution, "solution");
            Guard.ArgumentNotNull(processAndBreak, "processAndBreak");

            foreach (Project project in solution.Projects)
            {
                bool shouldBreak = false;
                if (!(project.Object is SolutionFolder))
                {
                    shouldBreak = processAndBreak(project);
                    if (shouldBreak)
                    {
                        return;
                    }
                }
                shouldBreak = ForEachProjectInternal(project.ProjectItems, processAndBreak);
                if (shouldBreak)
                {
                    return;
                }
            }
        }
Exemple #25
0
        public static List <string> ProcessSolution(
            this EnvDTE.Solution solution
            )
        {
            if (solution is null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

            ThreadHelper.ThrowIfNotOnUIThread();


            var projectList = solution.GetAllProjectsRecursively();

            var filePaths = new List <string>();

            foreach (EnvDTE.Project prj in projectList)
            {
                filePaths.AddRange(prj.ProcessProject());
            }

            return(filePaths);
        }
Exemple #26
0
        /// <summary>
        /// Search Running Object Table for a running VisualStudio instance which has open a particular solution.
        /// Typical usage might be EnvDTE.Solution sln = DesignTime.GetVisualStudioInstanceBySolution(@"\\My Solution\.sln$")
        /// </summary>
        /// <param name="solution_file_regex">Regular expression matching the solution fullname</param>
        /// <returns>The Solution object if a match was found, null otherwise</returns>
        public static EnvDTE.Solution GetVisualStudioInstanceBySolution(string solution_file_regex)
        {
            System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(solution_file_regex);

            IRunningObjectTable runningObjectTable;

            GetRunningObjectTable(0, out runningObjectTable);

            IEnumMoniker monikerEnumerator;

            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();

            IMoniker[] monikers   = new IMoniker[1];
            IntPtr     numFetched = IntPtr.Zero;

            while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
            {
                IBindCtx ctx;
                CreateBindCtx(0, out ctx);

                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);
                if (re.IsMatch(runningObjectName))
                {
                    object runningObjectVal;
                    runningObjectTable.GetObject(monikers[0], out runningObjectVal);
                    EnvDTE.Solution sln = runningObjectVal as EnvDTE.Solution;
                    if (sln != null)
                    {
                        return(sln);
                    }
                }
            }

            return(null);
        }
Exemple #27
0
 public static void WalkSolution(EnvDTE.Solution solution)
 {
     doSolution(solution);
     WalkProjects(solution.Projects);
 }
Exemple #28
0
 public ProSolution(EnvDTE.Solution sln)
 {
     prosln = sln;
     proFiles = new List<ProFileContent>();
 }
        public void ClearFiles(ClearFilesArgs clearFilesArgs)
        {
            try
            {
                TryHelper.Run(() => CleanUp());

                //If it throws exeption you may want to retry couple more times
                EnvDTE.Solution soln = GetSolution(clearFilesArgs);

                if (!String.IsNullOrWhiteSpace(clearFilesArgs.ProyectFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Limpiando '{0}'", Path.GetFileName(clearFilesArgs.ProyectFile)));
                    }
                }
                else if (!String.IsNullOrWhiteSpace(clearFilesArgs.SoluctionFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Limpiando '{0}'", Path.GetFileName(clearFilesArgs.SoluctionFile)));
                    }
                }

                if (String.IsNullOrWhiteSpace(clearFilesArgs.FilesFile))
                {
                    TryHelper.Run(() => soln.DTE.Commands.Raise(Settings.Default.GuidCodeMaidCommandCleanupAllCodeString, Settings.Default.CmdIDCodeMaidCleanupAllCode, null, null));
                }
                else
                {
                    ProjectItemIterator iterator = new ProjectItemIterator(soln);
                    String[]            files    = File.ReadAllLines(clearFilesArgs.FilesFile).Select(f => Path.GetFileName(f)).ToArray();

                    foreach (var addedItem in iterator)
                    {
                        string itemName = TryHelper.Run(() => addedItem.Name);

                        string kind = TryHelper.Run(() => addedItem.Kind);

                        if (kind == ProjectKinds.vsProjectKindSolutionFolder || kind == folderKindGUID)
                        {
                            continue;
                        }

                        if (files.Select(f => String.Compare(itemName, f, true) == 0).Count() == 0)
                        {
                            continue;
                        }

                        if (!clearFilesArgs.MinimumOutput)
                        {
                            Console.WriteLine(String.Format("\tLimpiando {0}...", itemName));
                        }

                        TryHelper.Run(() =>
                        {
                            // Console.WriteLine(nameFile);
                            addedItem.Open(Constants.vsViewKindCode);
                            addedItem.Document.Activate();

                            addedItem.Document.DTE.Commands.Raise(Settings.Default.GuidCodeMaidCommandCleanupActiveCodeString, Settings.Default.CmdIDCodeMaidCleanupActiveCode, null, null);

                            addedItem.Save();
                        });

                        if (clearFilesArgs.MinimumOutput)
                        {
                            Console.WriteLine(itemName);
                        }
                    }
                }

                TryHelper.Run(() => soln.Close());

                if (!String.IsNullOrWhiteSpace(clearFilesArgs.ProyectFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Finalizado limpieza '{0}'", Path.GetFileName(clearFilesArgs.ProyectFile)));
                    }
                }
                else if (!String.IsNullOrWhiteSpace(clearFilesArgs.SoluctionFile))
                {
                    if (!clearFilesArgs.MinimumOutput)
                    {
                        Console.WriteLine(String.Format("Finalizado limpieza '{0}'", Path.GetFileName(clearFilesArgs.SoluctionFile)));
                    }
                }
            }
            finally
            {
                TryHelper.Run(() => CleanUp());
            }
        }
        static readonly XNamespace xNamespace           = @"http://schemas.microsoft.com/winfx/2006/xaml"; // Used for example for "x:Name" attributes.

        public static IEnumerable <XElement> GetAppDotXamlResources(EnvDTE.Project currentProject, EnvDTE.Solution currentSolution, out string appDotXamlFullPath)
        {
            // Attempt to find the file "App.xaml":
            ProjectItem appDotXaml = FindAppDotXaml(currentProject, currentSolution);

            if (appDotXaml != null)
            {
                // Get the full path:
                appDotXamlFullPath = appDotXaml.Properties.Item("FullPath").Value.ToString();

                // Get the file content:
                string appDotXamlContent = File.ReadAllText(appDotXamlFullPath);

                // Remove the content of all the "HtmlPresenter" nodes, because the content may be not well formatted and may lead to a syntax error when parsing the XDocument:
                appDotXamlContent = HtmlPresenterRemover.RemoveHtmlPresenterNodes(appDotXamlContent);

                // Load the file as XML:
                XDocument xdoc = XDocument.Parse(appDotXamlContent);

                // Get the resources:
                var applicationDotResourcesNode = xdoc.Descendants(DefaultXamlNamespace + "Application.Resources").FirstOrDefault();
                if (applicationDotResourcesNode != null)
                {
                    IEnumerable <XElement> elementsInsideApplicationDotResourcesNode = applicationDotResourcesNode.Elements(); // This is either <ResourceDictionary>...</ResourceDictionary> or it is the list of resources (in case that <ResourceDictionary>...</ResourceDictionary> is implied).

                    // Determine whether the <ResourceDictionary> tag is omitted (implicit) or explicitly specified:
                    bool isTheResourceDictionaryTagExplicitlySpecified =
                        elementsInsideApplicationDotResourcesNode.Any() && elementsInsideApplicationDotResourcesNode.First().Name == (DefaultXamlNamespace + "ResourceDictionary");

                    // Change all the the resources "x:Name" into "x:Key" so that we do not get an error if there are two entries with the same "x:Name" in the whole document:
                    if (isTheResourceDictionaryTagExplicitlySpecified)
                    {
                        ChangeAllXNameIntoXKey(elementsInsideApplicationDotResourcesNode.First());
                    }
                    else
                    {
                        ChangeAllXNameIntoXKey(applicationDotResourcesNode);
                    }

                    return(elementsInsideApplicationDotResourcesNode);
                }
            }

            // Failure:
            appDotXamlFullPath = null;
            return(null);
        }
 /// <summary>
 /// Initializes the members of the SolnExtender class.
 /// </summary>
 /// <param name="sln">DTE.Solution object.</param>
 /// <param name="ExtenderCookie">Cookie value that identifies the Extender to its Site.</param>
 /// <param name="ExtenderSite">Site object for the Extender.</param>
 public void Init(EnvDTE.Solution sln, int ExtenderCookie, EnvDTE.IExtenderSite ExtenderSite)
 {
     Site   = ExtenderSite;
     Cookie = ExtenderCookie;
     Sol    = sln;
 }