Process Macro variables into T4 TextTemplate RRS feed

  • Question

  • I've a problem when I try to invoke the text transformation in a VSExtension.

    // Get the text template service: 

    ITextTemplating t4 = serviceProvider.GetService(typeof(STextTemplating))  as ITextTemplating;

    var vsHostEngine = t4 as ITextTemplatingEngineHost;

    ITextTemplatingSessionHost sessionHost = t4 as ITextTemplatingSessionHost;

    sessionHost.Session = sessionHost.CreateSession();

    sessionHost.Session["Rigenerate"] = parameter;

    TemplateCallBack templateCallBack = new TemplateCallBack();

    // Process a text template: 

    string result = t4.ProcessTemplate(templateFullFilePath, templateContent, templateCallBack)

    When I Call t4.ProcessTemplate(....) the template engine don't process the macro variables $(SolutionDir) (for example) and this issue generate in a template process error.

    My Question is: how I can I do to resolve the MacroVariables?

    Tuesday, December 6, 2016 2:53 PM

All replies

  • Hi DavideSattin,

    According to your description, it seems that you want to retrieve macro variables value. If it is the case. I think that Project class could achieve it.  like this:

    string webPath = @"D:\Project\Data\WebApp\WebFormApp\WebFormApp.csproj";
    var webp = new Project(webPath);
    var test = webp.GetPropertyValue("Configuration");

    Please add reference Microsoft.Build

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 7, 2016 5:46 AM