src/T4Toolbox.VisualStudio/OutputFileManager.cs
/// <summary>
/// Deletes the specified <paramref name="item" /> and its parent folders if they are empty.
/// </summary>
/// <param name="item">
/// A Visual Studio <see cref="ProjectItem" />.
/// </param>
/// <remarks>
/// This method correctly deletes empty parent folders in C# and probably
/// Visual Basic projects which are implemented in C++ as pure COM objects.
/// However, for Database and probably WiX projects, which are implemented
/// as .NET COM objects, the parent collection indicates item count = 1
/// even after its only child item is deleted. So, for new project types,
/// this method doesn't delete empty parent folders. However, this is probably
/// desirable for Database projects that create a predefined, empty folder
/// structure for each schema. We may need to solve this problem in the
/// future by recording which folders were actually created by the code
/// generator in the log file and deleting the empty parent folders when
/// the previously generated folders become empty.
/// </remarks>
Deletes the specified  and its parent folders if they are empty.
Deletes the specified and its parent folders if they are empty .
private static void DeleteProjectItem(ProjectItem item)
        {
            ProjectItems parentCollection = item.Collection;
            item.Delete();
            if (parentCollection.Count == 0)
            {
                var parent = parentCollection.Parent as ProjectItem;
                if (parent != null && parent.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
                {
                    DeleteProjectItem(parent);
                }
            }
        }
private static void DeleteProjectItem ( ProjectItem item ) { ProjectItems parentCollection = item . Collection ; item . Delete ( ) ; if ( parentCollection . Count == 0 ) { var parent = parentCollection . Parent as ProjectItem ; if ( parent != null && parent . Kind == EnvDTE . Constants . vsProjectItemKindPhysicalFolder ) { DeleteProjectItem ( parent ) ; } } }
Deletes the specified  and its parent folders if they are empty.
Deletes the specified and its parent folders if they are empty .
item
ProjectItem
A Visual Studio .
A Visual Studio .
remarks
This method correctly deletes empty parent folders in C# and probably
Visual Basic projects which are implemented in C++ as pure COM objects.
However, for Database and probably WiX projects, which are implemented
as .NET COM objects, the parent collection indicates item count = 1
even after its only child item is deleted. So, for new project types,
this method doesn't delete empty parent folders. However, this is probably
desirable for Database projects that create a predefined, empty folder
structure for each schema. We may need to solve this problem in the
future by recording which folders were actually created by the code
generator in the log file and deleting the empty parent folders when
the previously generated folders become empty.
This method correctly deletes empty parent folders in C# and probably Visual Basic projects which are implemented in C ++ as pure COM objects . However for Database and probably WiX projects which are implemented as . NET COM objects the parent collection indicates item count = 1 even after its only child item is deleted . So for new project types this method doesn ' t delete empty parent folders . However this is probably desirable for Database projects that create a predefined empty folder structure for each schema . We may need to solve this problem in the future by recording which folders were actually created by the code generator in the log file and deleting the empty parent folders when the previously generated folders become empty .