2

I want to pass some additional parameters to my T4 code generation templates in my TDS projects. In the TDS Projects Code Generation properties tab, there is a field for passing additional code generation properties, but I can't get this to work. I thought it would work like this:

Passing the parameters like this:

TDS Project Code Generation Properties tab

and then pick up the value in the T4 template like this:

<#@ parameter name="MyProperty" type="System.String" #>
<#
   if (MyProperty == ...) 
      ...
#>

But the above doesn't work. The value of MyProperty is always empty when running the T4 generation. What am I doing wrong? Have I perhaps completely misunderstood this feature?

(I'm using TDS 6.0.0.18, i.e. latest version when writing this)

2
  • Not sure how to fix your problem, but have you looked in to Leprechaun for CodeGen? Its so much better than T4!
    – Richard Seal
    Jan 25 at 15:22
  • Thanks, but switching to Leprechaun would be a major change in this project.
    – mikaelnet
    Jan 25 at 18:26
1

You try to get a property like it is passed into a session variable. But TDS passes Additional Code Generation Properties into SitecoreItem model. That is why you need to use a different approach to get values.

You are able to get your properties from SitecoreItem type, AdditionalProperties field ynside your Base Project Transform File (usually, GlassItemVX.tt):

e.g.

<#@ parameter name="Model" type="HedgehogDevelopment.SitecoreProject.VSIP.CodeGeneration.Models.SitecoreItem" #>
string myProperty = Model.AdditionalProperties["MyProperty"];
Write(myProperty);#>

Will generate this outcome:

MyValue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.