Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

TangibleTyper2
#1 Posted : Friday, May 5, 2017 12:56:13 PM(UTC)
TangibleTyper2
Rank: Newbie

Groups: Member
Joined: 5/5/2017(UTC)
Posts: 1

So when running through the TemplateFileManagerV2.1.ttinclude code I noticed GetAllProjects does not actually return all projects as it does not explore folders beneath the top level[0], and instead assumes that they are projects underneath.

If you have any nested folders this can be a problem for WriteVsProperties, as it relies on GetAllSolutionItems, which will not explore all project items, as so will not assign the properties to items nested in folders.

To fix this I offer GetAllProjectsRecursiveFromSolution [wrapper fnc] and GetAllProjectsRecursive [recursive caller] instead of GetAllProjects. So all GetAllProjects should be replaced with GetAllProjectsRecursiveFromSolution

Code:

public static IEnumerable<EnvDTE.Project> GetAllProjectsRecursiveFromSolution(EnvDTE.DTE dte)
    {
        List<EnvDTE.Project> projectList = new List<EnvDTE.Project>();
        var folders = dte.Solution.Projects.Cast<EnvDTE.Project>().Where(p => p.Kind == EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder);

        foreach (EnvDTE.Project folder in folders)
        {
            foreach (EnvDTE.ProjectItem item in folder.ProjectItems)
            {
				if(item.Object == null)
                {
					continue;
                }
				if((item.Object as EnvDTE.Project).Kind ==  EnvDTE.Constants.vsProjectKindSolutionItems )
				{
                    projectList.AddRange(GetAllProjectsRecursive(item.Object as EnvDTE.Project));
				}
                else if (item.Object is EnvDTE.Project)
                {
                    projectList.Add(item.Object as EnvDTE.Project);
                }
            }
        }
        var projects = dte.Solution.Projects.Cast<EnvDTE.Project>().Where(p => p.Kind != EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder);
        projectList.AddRange(projects);

        return projectList;
    }
    public static IEnumerable<Project> GetAllProjectsRecursive(EnvDTE.Project folder)
    {
        List<EnvDTE.Project> projectList = new List<EnvDTE.Project>();

        if (folder.ProjectItems != null)
        {
            foreach (EnvDTE.ProjectItem item in folder.ProjectItems)
            {
				if(item.Object == null)
                {
					continue;
                }
				if((item.Object as EnvDTE.Project).Kind ==  EnvDTE.Constants.vsProjectKindSolutionItems )
				{
                    projectList.AddRange(GetAllProjectsRecursive(item.Object as EnvDTE.Project));
				}
                else if (item.Object is EnvDTE.Project)
                {
                    projectList.Add(item.Object as EnvDTE.Project);
                }
            }
        }
        return projectList;
    }


I hope this can be of use!

[0] top level being under the sln. [The vsProjectKindSolutionFolder folders]
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2020, Yet Another Forum.NET
This page was generated in 0.085 seconds.

Authorization on the site

For an authorized user opens up new possibilities

Login

Password