Generating stubs for custom code

Feb 19, 2009 at 6:56 PM
I want to generate two-files per entity using partial classes.  The first class is where the code generate code goes.  The second class is where the developer can add custom changes to the class.  For convenience purposes, I want to code generate the custom file stub, but I don't want to overwrite it the next time the generator runs.
So I'm checking for file existence before rendering to file. But the problem is that T4 Toolbox wants to remove the file for VS if I don't render it. Is there any facilities in T4 Toolbox to get it to leave the file alone if I don't want to render it. This is what I'm trying to do from the code ...
  protected override void RunCore()
CommandTemplate ct = new CommandTemplate();
CommandCustomTemplate cct = new CommandCustomTemplate();

foreach (Command cmd in CommandSet.Commands)
ct.CommandSet = CommandSet;
cct.CommandSet = CommandSet;
ct.Command = cmd;
cct.Command = cmd;
ct.RenderToFile(cmd.Name + "Command.Generator.cs");

string templateDir = System.IO.Path.GetDirectoryName(TransformationContext.Host.TemplateFile);
string fullName = System.IO.Path.Combine(templateDir, cmd.Name + "Command.cs");

if (!File.Exists(fullName))
cct.RenderToFile(cmd.Name + "Command.cs");
Feb 19, 2009 at 8:08 PM
Edited Feb 19, 2009 at 8:10 PM
I suggest you read this thread: Template creation question. Perhaps, two of us could convince Oleg to implement it!

George J.
Feb 20, 2009 at 11:38 AM
Yeah, yeah :). I'm not opposed to it. Ping me in a week or so. I should be done with the  new OutputManager I'm working on right now and we can figure out how to implement this.