Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Call TextTemplateAction from within a "CreateProject" action
 

Call TextTemplateAction from within a "CreateProject" action

I am writing a Guidance Package that is for an architecture similar to CAB - there is a shell and it can load modules. The solution has a folder called Modules and I want a recipe that can create a module in this solution folder. Say the developer wants a module called "ClientModule" the recipe will create another solution folder under Modules called "ClientModule" and under this sub-folder create 2 projects: One called "ClientModule" and one called "ClientModulePublisher".

To do this I looked at the SCSF guidance package and "butchered" my own version of theirUnfoldModuleProjectAction action. This action is pretty straight-forward: create the solution folder and then call the "AddFromTemplate" method on the solution folder.

The problem comes in with substitution of $parameters$ in the template file. For the module project, I have a class called Module.cs with a placeholder called $ModuleName$. No matter how I try to do it, the parameter is never substituted for the actual ModuleName value (this is a RecipeArgument). This works for the SCSF package, but I cannot get it to work for my template, though I cannot see any differences.

So I tried to turn the VSTemplate into a T4 template. The template is really nothing fancy and has only 1 property (for substitution) declared as follows:

<#@ property processor="PropertyProcessor" name="ModuleName" #>

Then I tried to call the TextTemplateAction from code to do the rendering as follows:

using (TextTemplateAction action = new TextTemplateAction())
{
Site.Container.Add(action);
action.Template = classTemplate;
action.Execute();
return action.Content;
}

This failed when the Execute() method was called - the exception said that property "ModuleName" had not been supplied.

However, if I use the recipe to call the T4 transform, it works perfectly. The Action looks as follows:


<Action Name="RenderModuleClass" Type="TextTemplateAction" Template="Text\Module.cs.t4">
<
Input Name="ModuleName" RecipeArgument="ModuleName"
/>
<
Output Name="Content"
/>
</
Action>


The question is, how can I call the TextTemplateAction from the code? Am I missing something that "initializes" the dictionary that the rendering engine uses (incidentally, if I use GetService<IDictionary>() to get the dictionary service, the ModuleName is there).

Any ideas?


Project Manager - Real People
  • Edited byColinD Friday, July 25, 2008 9:07 AMchanged position of XML paragraph
  •  
ColinD  Friday, July 25, 2008 9:05 AM
Hi

You need to set up the properties of your T4 template using the Configure() method of TextTemplateAction.

like this :

StringDictionnary dic = new StringDictionnary ()
dic.Add("ModuleName" , value_of_module_name ) ;
action.Configure(dic) ;
action.Execute()

Hope that helps
  • Proposed As Answer byJose Escrich Tuesday, August 05, 2008 4:14 PM
  •  
rochesebastien  Tuesday, August 05, 2008 1:43 PM

You can use google to search for other answers

Custom Search

More Threads

• What is the status of GAT? Why not use Codesmith?
• How to add a template without opening it.
• Can't get Recipe arguments into template - using UnfoldTemplateAction
• CommandBars
• Installation error
• Installing GAX breaks Orcas C# new project creation
• Keyref warning
• GAT/GAX for VS2005 RTM released!
• Server Application Unavailable
• Problems installing a Guidance Package