This project is read-only.

How to not delete a file if it wasn't generated ?

Jun 11, 2010 at 10:53 AM
Edited Jun 11, 2010 at 10:58 AM
Hi, I'm using t4toolbox to generate concretes class from interface. This way there is a generated file with all the properties, and i implement all the methods in a second file (using partial). I want the file containing the method to be generated only if it doesn't exists. So to do this i use to template. One for the always generated file, and another for the first time generated file (containing methods). But t4toolbox delete my method file the second time i run my template :( So my question would be : is there a way to tell t4toolbox not to remove my files ? My code : {{ var dte = T4Toolbox.TransformationContext.DTE; var infos = (new ModelAnalyzer(dte.Solution)).Analyze(this.Path); foreach (var interInfo in infos) { var tmpl = new ModelTemplate(); tmpl.InterfaceInfo = interInfo; tmpl.Render(); var partialPath = System.IO.Path.Combine(this.Path, "Concretes", interInfo.Name.Substring(1) + ".cs"); if (!File.Exists(partialPath) && interInfo.Functions.Count > 0) { var partialTmpl = new ModelPartialTemplate(); partialTmpl.InterfaceInfo = interInfo; partialTmpl.Render(); /*TransformationContext.TransformationEnded += ((c, d) => { var projectItem = TransformationContext.FindProjectItem(partialPath); if (projectItem != null) projectItem.Properties.Item("IsDependentFile").Value = false; });*/ } } }}
Jun 11, 2010 at 11:04 AM
Found the answer : this.Output.PreserveExistingFile = true;