src/T4Toolbox.VisualStudio/OutputFileManager.cs
/// <summary>
/// Finds project item collection for the output file in the currently loaded Visual Studio solution.
/// </summary>
/// <param name="output">
/// An <see cref="OutputFile" /> that needs to be added to the solution.
/// </param>
/// <returns>
/// A <see cref="ProjectItems" /> collection where the generated file should be added.
/// </returns>
Finds project item collection for the output file in the currently loaded Visual Studio solution.
Finds project item collection for the output file in the currently loaded Visual Studio solution .
private ProjectItems FindProjectItemCollection(OutputFile output)
        {
            string outputFilePath = this.GetFullPath(output.Path);
            ProjectItems collection; 
            string relativePath; 
            string basePath; 
            if (!string.IsNullOrEmpty(output.Project))
            {
                Project project = this.projects[this.GetFullPath(output.Project)];
                collection = project.ProjectItems;
                relativePath = FileMethods.GetRelativePath(project.FullName, outputFilePath);
                basePath = Path.GetDirectoryName(project.FullName);
            }
            else if (!string.IsNullOrEmpty(output.Directory))
            {
                collection = this.input.ContainingProject.ProjectItems;
                relativePath = FileMethods.GetRelativePath(this.input.ContainingProject.FullName, outputFilePath);
                basePath = Path.GetDirectoryName(this.input.ContainingProject.FullName);
            }
            else
            {
                collection = this.input.ProjectItems;
                relativePath = FileMethods.GetRelativePath(this.inputFile, outputFilePath);
                basePath = Path.GetDirectoryName(this.inputFile);
            }
            if (relativePath.StartsWith("." + Path.DirectorySeparatorChar, StringComparison.Ordinal))
            {
                relativePath = relativePath.Substring(relativePath.IndexOf(Path.DirectorySeparatorChar) + 1);
                while (relativePath.Contains(Path.DirectorySeparatorChar))
                {
                    string folderName = relativePath.Substring(0, relativePath.IndexOf(Path.DirectorySeparatorChar));
                    ProjectItem folder = AddFolder(collection, folderName, basePath);
                    collection = folder.ProjectItems;
                    relativePath = relativePath.Substring(folderName.Length + 1);
                    basePath = Path.Combine(basePath, folderName);
                }
            }
            return collection;
        }
private ProjectItems FindProjectItemCollection ( OutputFile output ) { string outputFilePath = this . GetFullPath ( output . Path ) ; ProjectItems collection ; string relativePath ; string basePath ; if ( ! string . IsNullOrEmpty ( output . Project ) ) { Project project = this . projects [ this . GetFullPath ( output . Project ) ] ; collection = project . ProjectItems ; relativePath = FileMethods . GetRelativePath ( project . FullName , outputFilePath ) ; basePath = Path . GetDirectoryName ( project . FullName ) ; } else if ( ! string . IsNullOrEmpty ( output . Directory ) ) { collection = this . input . ContainingProject . ProjectItems ; relativePath = FileMethods . GetRelativePath ( this . input . ContainingProject . FullName , outputFilePath ) ; basePath = Path . GetDirectoryName ( this . input . ContainingProject . FullName ) ; } else { collection = this . input . ProjectItems ; relativePath = FileMethods . GetRelativePath ( this . inputFile , outputFilePath ) ; basePath = Path . GetDirectoryName ( this . inputFile ) ; } if ( relativePath . StartsWith ( " " + Path . DirectorySeparatorChar , StringComparison . Ordinal ) ) { relativePath = relativePath . Substring ( relativePath . IndexOf ( Path . DirectorySeparatorChar ) + 1 ) ; while ( relativePath . Contains ( Path . DirectorySeparatorChar ) ) { string folderName = relativePath . Substring ( 0 , relativePath . IndexOf ( Path . DirectorySeparatorChar ) ) ; ProjectItem folder = AddFolder ( collection , folderName , basePath ) ; collection = folder . ProjectItems ; relativePath = relativePath . Substring ( folderName . Length + 1 ) ; basePath = Path . Combine ( basePath , folderName ) ; } } return collection ; }
Finds project item collection for the output file in the currently loaded Visual Studio solution.
Finds project item collection for the output file in the currently loaded Visual Studio solution .
// collection to which output file needs to be added // path from the collection to the file // absolute path to the directory to which an item is being added // If output file needs to be added to another project // If output file needs to be added to another folder of the current project // Add the output file to the list of children of the input file // make sure that all folders in the file path exist in the project. // Remove leading .\ from the path
A  collection where the generated file should be added.
A collection where the generated file should be added .
output
OutputFile
An  that needs to be added to the solution.
An that needs to be added to the solution .