This is a very important feature to me so I decided to investigate this further on my own. Here are a few of my observations.
First, adding the "DependentUpon" build property DOES work. The problem is that Visual Studio does not refresh the solution explorer to reflect this. If you immediately save and then close the solution after code generation and
then open it again, the files are displayed nested as one would expect.
//Render Main Class
MainTemplate myMainTemplate =
myMainTemplate.Output.PreserveExistingFile = true;
myMainTemplate.Output.Project = "TestProject.csproj";
myMainTemplate.Output.File = "Class1.cs";
//Render Base Class
BaseTemplate myBaseTemplate =
myBaseTemplate.Output.Project = "TestProject.csproj";
myBaseTemplate.Output.File = "Class1_base.cs";
myBaseTemplate.Output.BuildProperties["DependentUpon"] = "Class1.cs";
Some have suggested that you can force a refresh by adding the following code. I tried to download the T4Toolbox source code and try this myself, however I could not get the source code to build.
Secondly, the automation API does offer a method to add dependent files. The code for this is below.
So, based on these two options, it may be easy to add support for dependent files. The first approach is to simply find a way to refresh the solution in Visual Studio and let users add the build property "DependentUpon". The second would
be to add Output.DependentUpon property and use the "AddFromFile" option in the API.
In the mean time, I am using the first approach as I don't need to regenerate my solutions often and it is not that bad.