index > Visual Studio Team System - Domain-Specific Language Tools > T4 Example of passing parameters to TextTransform using the -a co...

T4 Example of passing parameters to TextTransform using the -a co...


I want to pass command line parameters to a custom directive processor.

I expected to see the parameters in the arguments parameter on the ProcessDirective method of my custom directive processor.

Can anyone provide an example of this?

Brucec

You have to do next steps:

protected override void InitializeProvidesDictionary(string directiveName, IDictionary<string, string> providesDictionary)

{

base.InitializeProvidesDictionary(directiveName, providesDictionary);

providesDictionary["BaseSourceDir"] = base.Host.ResolveParameterValue(directiveName, "InstallerDefinitionDirectiveProcessor", "BaseSourceDir");

if (String.IsNullOrEmpty(providesDictionary["BaseSourceDir"]))

providesDictionary["BaseSourceDir"] = System.Environment.CurrentDirectory;

}

Now you can run command line: -a "!!BaseSourceDir!c:\\Projects\\SSO\\Implementation" or in template

<#@ InstallerDefinition processor="InstallerDefinitionDirectiveProcessor" requires="fileName='..\CustomPTCustomizationInstaller.pkgsetup'" provides="installerPackageModel=InstallerDefinition;BaseSourceDir=c:\\projects\\sso\\"#>

Also, I add this code to have all parameters as property of the TextTransformationTemplate:

protected override void GenerateTransformCode(string directiveName, StringBuilder codeBuffer, System.CodeDom.Compiler.CodeDomProvider languageProvider, IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments)

{

base.GenerateTransformCode(directiveName, codeBuffer, languageProvider, requiresArguments, providesArguments);

if ((StringComparer.InvariantCultureIgnoreCase.Compare(directiveName, "InstallerDefinition") == 0) && (languageProvider != null))

{

List<System.CodeDom.CodeMemberProperty> properties = new List<CodeMemberProperty>();

foreach (String argName in providesArguments.Keys)

{

// Create a property for the Model that delay-loads the model

System.CodeDom.CodeMemberProperty property= new System.CodeDom.CodeMemberProperty();

property.Name = argName;

property.Type = new System.CodeDom.CodeTypeReference(typeof(String));

property.Attributes = System.CodeDom.MemberAttributes.Public;

property.HasSet = false;

property.HasGet = true;

property.GetStatements.Add(new CodeMethodReturnStatement(new System.CodeDom.CodePrimitiveExpression(providesArguments[argName])));

properties.Add(property);

}

CodeGeneratorOptions options1 = new CodeGeneratorOptions();

options1.BlankLinesBetweenMembers = true;

options1.IndentString = "\t";

options1.VerbatimOrder = true;

options1.BracingStyle = "C";

using (StringWriter writer1 = new StringWriter(codeBuffer, CultureInfo.InvariantCulture))

{

foreach(System.CodeDom.CodeMemberProperty p in properties)

languageProvider.GenerateCodeFromMember(p, writer1, options1);

}

}

}

Evgeny Popov
Thanks EP - that clarifies a few things for me.
Brucec
reply 3

You can use google to search for other answers

 

More Articles

February CTP of DSL Tools is live in the Visual Studio 2005 SDK F...
Migrating to May CTP: Text Template Problem
Reflecting domain property value on shape colour, outline etc..
Beginner question about the use of DSL Tools
IE7 Beta 2 and DSL Tools
How to determine if a model passes validation?
t4 in a custom/stand alone tool
Inheritance Restriction?
How to add or remove template files in the target (exp) environne...
How to make a Domain Relationship visible in a class's shape on D...
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Compartment Shape for Model
Shape Icon and Shape Tool Minor Bug
Xsd To DslDefinition.dsl transformation
change literals of enumeration property …
I get a null reference exception when ad…
Reminder Web Chat this Tuesday
How to Dynamically create shapes
How to Calculate a property's value
How are new objects created in a DSL?
Drop-down list to edit 1-* relationships
How do I use the DSL that I have created…
Concept's Properties
Suggestion - Context Menu: Override Beha…
Dynamically determining link type
Custom Rules in June CTP

Hot Articles

Comments and CommentShapes
How to add a custom rule that listens on…
Copy/Paste
CMDS: Missing package guid for commands …
How do you Add F1 Help and ToolTips to a…
Infopath as editor
Question on property generator
Background Picture
Why the f$%^&* does the DSL tools as…
Come join the largest group on the DSL a…
Finding the associated presentation elem…
DSL Tools support for Visual Studio edit…
Using existing Enumerations
Is there any DSL Specifications?
Crash of visual studio when model is inc…

Recommend Articles

Inheritance Restriction?
How to know if OnShapeInserted was initi…
DSL and visual studio
DSL using languages
Template Fix: Text templating fails with…
filtering reference dropdowns in the pro…
Error crearting DSL prokject
How-to: create a custom tool that runs d…
Add a toolbar to the dsl designer surface
How to move shapes within diagram progra…
connections restrictions between shapes …
Why must the ShapeField's value be assoc…
Domain model designer
How do you Add F1 Help and ToolTips to a…
protected internal