Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > How to generate a template from an existing class file
 

How to generate a template from an existing class file

How to generate a template from an existing class file?

A walkthrough sample available

thanks

vsv

vsv02  Tuesday, August 21, 2007 10:11 PM
You would usually start from a working class file and then replace the specifics from your file to use variables (note the highlighted text):

using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.ComponentModel;
using Clarius.GuidanceAutomation.Library.Actions;

namespace $rootnamespace$
{
public class $safeitemrootname$ : ActionBase
{
protected override void OnExecute()
{
// TODO: add your custom action logic here
}

protected override void OnUndo()
{
// TODO: add code to undo the changes made in the Execute method
// this Undo method will be called if the execution of a recipe is cancelled
}
}
}


You can also use the "Export Template" functionallity of Visual Studio to get your working .vstemplate files corresponding to the .xxproj and other files included in your project.

I recommend that you read through the docs of VS Templates to catchup on this.

If you're new to GAX you should also take a look at the GAX Hand on Labs which is a word document plus source code for a sample package that will showcase common tasks (as this one) performed by a guidance package.

You can get an updated version of this GAX HOL from SFT at: http://softwarefactoriestoolkit.net/

thanks,
-Victor.

vga  Tuesday, August 21, 2007 10:57 PM
You would usually start from a working class file and then replace the specifics from your file to use variables (note the highlighted text):

using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.ComponentModel;
using Clarius.GuidanceAutomation.Library.Actions;

namespace $rootnamespace$
{
public class $safeitemrootname$ : ActionBase
{
protected override void OnExecute()
{
// TODO: add your custom action logic here
}

protected override void OnUndo()
{
// TODO: add code to undo the changes made in the Execute method
// this Undo method will be called if the execution of a recipe is cancelled
}
}
}


You can also use the "Export Template" functionallity of Visual Studio to get your working .vstemplate files corresponding to the .xxproj and other files included in your project.

I recommend that you read through the docs of VS Templates to catchup on this.

If you're new to GAX you should also take a look at the GAX Hand on Labs which is a word document plus source code for a sample package that will showcase common tasks (as this one) performed by a guidance package.

You can get an updated version of this GAX HOL from SFT at: http://softwarefactoriestoolkit.net/

thanks,
-Victor.

vga  Tuesday, August 21, 2007 10:57 PM

HoL uses this format

<#= this.TargetNamespace #>

while your example has $safeitemrootname$

which one is correct. when to use them.

thanks

vsv

vsv02  Wednesday, August 22, 2007 11:23 PM
They're different approaches.

The one I pointed you to is just a simple .vstemplate with "variables" that are known to VS and VS will replace them. You can look up VS docs in order to see a list of supported variables and what they translate to.

The example you point out uses a .t4 file which would be transformed by GAX -not VS- based on inputs (usually recipe arguments or action output, in the case you point out that "TargetNamespace" is very probably a recipe argument that is filled in a wizard page).

Note they both are "dynamic" ways, which one to use would mostly depend on what you're trying to achieve. If you can post more details on that I could try to guide you where to go.

thanks,
-Victor.
vga  Thursday, August 23, 2007 9:51 AM

Yes I was trying to extend what HoL does using recipe. I want to create a recipe based on inputs.

I was trying to generate a class in a BLL layer consuming DLL class & calling its methods.

Now I may be understanding it a little bit better.

So *.template file is different than *.t4 files.

So template is understood by Visual Studio & *.t4 file is understood by GAX.

I think my correct question is how to generate a .t4 file using an existing class file?

thanks

vsv

vsv02  Thursday, August 23, 2007 4:49 PM
Hi, I'm not sure if you are asking again but anyway this is what I may do: Once you have the C# class file you just need to create another file (or rename the existing one) with the .t4 extension, add the t4 directives (language, assemblies, properties, etc), put the code in it (if you created the file), and replace the text you want to generate with <#= #> tokens. This is a manual task but the SFT's T4 Editor may help (for editing and running a Preview of the transformation).

HTH,
-Adrian
Adrian Alonso  Monday, August 27, 2007 3:32 PM

You can use google to search for other answers

Custom Search

More Threads

• Not able to install on vista x64
• Challenge in writing a T4 template with Arguments created onthe fly based on a xsd file
• "Add new module" recipe customization
• Throwing error when data set has large amount of data binding with crystal report
• cross-recipe arguments
• same problem
• Create a Template
• Action type??
• Wizard size and colors
• VS2008 Standard vs Professional