This project is read-only.


Sep 15, 2009 at 2:53 PM


Visual studio project items have the possibility to specify that they are depending upon another item and so they get displayed as nested items inside project explorer. I was wandering if there is such an option to specify also the dependentupon option:

Template.Output.Project = @"Project.csproj";

Template.Output.File = @"myclass.generated.cs";

Template.Output.DependentUpon = @"myclass.cs";





Sep 15, 2009 at 9:33 PM
Edited Sep 15, 2009 at 9:34 PM


Currently, T4 Toolbox doesn't allow you to do this. If you leave Output.Project empty and don't specify directory/path in Output.File, the generated file will be "DependentUpon" the .tt file itself. I could see how what you described could be useful in compbination with generation of an empty "myclass.cs" that serves as a starting point for a developer to customize.


Sep 16, 2009 at 10:21 AM


Thank you for your quick reply. Well indeed this is my exact use case, an empty class file for developer and a generated class as base. Oh well, back to work then, trying some other way. Maybe in the near future this will be supported.




May 21, 2010 at 12:52 AM

How easy would it be to modify the current code base to support that? Isn't DependentUpon a BuildProperty?

May 21, 2010 at 8:00 PM

Yes, it is a build property, but the automation API doesn't support it as such. Logic would need to be modified to insert the output file in the apprpropriate project item collection instead.


Aug 15, 2010 at 11:29 PM


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 = new MainTemplate(); 
myMainTemplate.Output.PreserveExistingFile = true;
myMainTemplate.Output.Project = "TestProject.csproj";
myMainTemplate.Output.File = "Class1.cs";

//Render Base Class
BaseTemplate myBaseTemplate = new BaseTemplate(); 
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.

DTE.ExecuteCommand("View.Refresh", "");


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.


May 8, 2011 at 10:32 PM

I'm trying call dte.ExecuteCommand("View.Referesh", "") to refresh de solution explorer but nothing happends.