#pragma warning disable VSTHRD010 // Accessing ... should only be done on the main thread. static IEnumerable <ProjectItem> GetDescendants(ProjectItem projectItem) { // VS will run the custom tool on the project item only if the document is open => Run the custom tool on any of the descendants, too. // VS will not run the custom tool if just the file is saved in background, and no document is open => Run the custom tool on all descendants and self. return(projectItem.GetIsOpen() ? projectItem.Descendants() : projectItem.DescendantsAndSelf()); }