none
How to transform T4 template dynamically through code in C# RRS feed

  • Question

  •  I have one MVC application project with T4 template of master page. (Site.tt) .

     site.tt will be transformed to Site.Master whenever i open the project. how can i do this?  (Need to transform the .tt file to .Master when i open the project)

    that means T4 template transformed dynamically through opening the specific project ..

    the T4 template is below

    Site.tt:


    <#@ template language="C#" HostSpecific="True" #>
    <#@ output extension=".Master" #>
    <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>

    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>
            <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
        </title>


    <body>

    </body>
    </html>

    Any help on this?

    Regards,

    Siva


    siva

    Tuesday, April 10, 2012 1:42 PM

Answers

  • Can't you just move  this file to a suitable location ?

    If you want to write to a location not allowed for an account you don't have much solution : either use an account that can or give the account you are using the right to to do so.  It seems much simpler to use a suitable location (you are not allowed to write to the root directory but you should be able to create a subdirectory under the root and write in this directory).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Wednesday, April 11, 2012 8:13 AM

All replies

  •  I have tried from below link:

    http://stackoverflow.com/questions/1612846/can-i-use-t4-programmatically-from-c

    System.Diagnostics.Process proc = new System.Diagnostics.Process();

    proc
    .EnableRaisingEvents = false;

    // Set text transform program (this could change according to the Windows version)
    proc
    .StartInfo.FileName = "C:\\Program Files (x86)\\Common Files\\microsoft shared\\TextTemplating\\10.0\\TextTransform.exe";

    // Specify T4 template file
    proc
    .StartInfo.Arguments = "C:\template.tt";

    proc
    .Start();

    it was working when i place the template file in other location (D /Some other drive) . but in my application i am using the template file in "C:" drive. so some administrator problem.

    when i open the VS2010 with admin permission it was working fine... but  i placed  the template file in some other location  of " C:\" drive . it was not working..

    please help me on this..


    siva

    Tuesday, April 10, 2012 1:48 PM
  • Hi,

    It doesn't does the transform as needed when you build the app ? Or even why do you need a T4 template in this case ? You could look as VS extensiblity to perhaps hook up something the project is opened but I would suggest to explain what you are trying to do as sometimes it can leads to better suggestion...

    For the second part on which location is this exactly ? It could depend on where exactly it is on the c: drive. In particular in non admin mode you are not supposed to be allowed to write to c:\ (what if you create a subfolder and move this file there ?)


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".




    Tuesday, April 10, 2012 2:08 PM
  • Hi,

    Thanks for your reply.

    I need any other solution to transform the T4 template file dynamically through C#. because while using Process concept  we need some admin permission to access the file from that location. 

    so am waiting for  any other solution to transform the T4 template file.

    Thanks,

    Siva


    siva

    Wednesday, April 11, 2012 4:16 AM
  • Can't you just move  this file to a suitable location ?

    If you want to write to a location not allowed for an account you don't have much solution : either use an account that can or give the account you are using the right to to do so.  It seems much simpler to use a suitable location (you are not allowed to write to the root directory but you should be able to create a subdirectory under the root and write in this directory).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Wednesday, April 11, 2012 8:13 AM