locked
Call T4 Action RRS feed

  • Question

  • Hi, is there any way to call a TextTemplateAction from an Action. The problem is setting the value for the PropertyProcessors.

    Thanks,

    Martin
    Thursday, October 18, 2007 1:00 AM

Answers

  • That's why you have a reference to 8.2 TextTemplateHost and you should use 8.1 instead of that. Try change the reference to 8.1 and it should works.

     

    hth

    jose.

    Friday, October 19, 2007 6:48 PM

All replies

  • Hi Martin,
    You should write your own action using the host directly, here http://weblogs.asp.net/jescrich/archive/2007/05/03/testing-t4-templates-using-the-gax-host.aspx
    you've an example how to invoke the TemplateHost and run the transformation,

    hth.
    jose.

    Thursday, October 18, 2007 11:58 PM
  • Thanks for the info, it helped a lot but i have a problem when I execute the template:

    string tempfile = Path.GetTempFileName();
                    string rutaTemplate = "";
                    TypeResolutionService typeResService = (TypeResolutionService)GetService(typeof(ITypeResolutionService));
                    Dictionary<string, PropertyData> dict = new Dictionary<string, PropertyData>();
                    dict.Add("ClassName", new PropertyData(modulo, typeof(string)));
                    dict.Add("ClassNameMin", new PropertyData(modulo.ToLower(), typeof(string)));
                    dict.Add("Namespace", new PropertyData("Tactics", typeof(string)));
                    dict.Add("Project", new PropertyData(projectPresenter, typeof(string)));
                    dict.Add("Suf", new PropertyData(sufijo, typeof(string)));
                    rutaTemplate = @"C:\Documents and Settings\Computer\Desktop\Codigo\TacticsConferenceSite\TacticsConferenceSite\Templates\Text\CrearModulePresenter.cs.t4";
                    TemplateHost host = new TemplateHost(Directory.GetCurrentDirectory(), dict);
                    host.TemplateFile = rutaTemplate;

                    ITextTemplatingEngine engine = new Engine();
                    string template = File.ReadAllText(host.TemplateFile);
                    string contenidoABMPresent = engine.ProcessTemplate(template, host);

                    using (StreamWriter sw = new StreamWriter(tempfile, false))
                    {
                        sw.WriteLine(contenidoABMPresent);
                    }
                    EnvDTE.ProjectItem item = CreateDirectoryPresenter();
                    item.ProjectItems.AddFromTemplate(tempfile, fileABMPresenter);
                    File.Delete(tempfile);

    When I execute engine.ProcessTemplate the HOST parameter is not properly set, i get an exception "Entry Point Not Found". Which directory is it supposed to look in the first argument of new TemplateHost?

    Thanks again,

    Martin
    Friday, October 19, 2007 12:11 PM
  • That's why you have a reference to 8.2 TextTemplateHost and you should use 8.1 instead of that. Try change the reference to 8.1 and it should works.

     

    hth

    jose.

    Friday, October 19, 2007 6:48 PM