This project is read-only.

How to use T4Toolbox in DSLTools projects?

Jul 27, 2009 at 12:03 AM

I've been using T4Toolbox for about a year now - it's an awesome tool!

Now I'm starting a new project with graphical DSL that is using DSL Tools. Out of the box the resulting project (Debugging) does not allow the use of T4Toolbox. I'm getting "strange" results that seems to depend on the number of transformation attempts:

"Usually" the first try leads to "A processor named 'T4Toolbox.DteProcessor' could not be found for directive named 'dte'", but not always - sometime it simply can't load T4Toolbox.

My goal is to use multiple file generation abilities of T4Toolbox - Template class.

Any suggestion how to do that would be highly appreciated.

Thanks for the great tool!

ms440

Jul 27, 2009 at 6:45 PM

@ms440

Thanks for pointing out this issue. I will test T4 Toolbox in a sample DSL solution to see if I can duplicate the issue. In the meantime, it would be helpful if you provide any specific error messages you received in your usage.

Oleg

 

Jul 28, 2009 at 3:32 PM

I ran into errors that sound similar to what you are describing while running the Class Diagram DSL sample under debugger. In particular, I got the error saying that it can't find T4Toolbox.tt. The problem was caused by the differences between the main Visual Studio hive and the "experimental" hive it uses during debugging of DSL samples. I was able to resolve it by resetting the experimental hive (Start->All Programs->Visual Studio 2008 SDK->Tools->Reset Microsoft visual Studio 2008 SP1 Experimental Hive) and rebuilding the sample project (to re-register the custom directive the sample defines). Please let me know if this doesn't work for you.

Oleg

Jul 28, 2009 at 11:45 PM

Hi Oleg,

 

Yes, I was having the same problem with T4Toolbox unavailable until I've reset the Experimental Hive. But this was a minor one :)

What I'm trying to do is to use the pattern described in http://www.olegsych.com/2009/03/t4-toolbox-generating-files-in-different-folders-and-projects/ - in one of the .tt templates in Debugging solution.

Here is an example

<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension=".txt" #>
<#@ include file="T4Toolbox.tt" #>
<#@ L3 processor="L3DirectiveProcessor" requires="fileName='Sample.L3'"  #>
Report template


<#= this.ComponentModel.Name #>

<#
	// inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" 
  // When you change the DSL Definition, some of the code below may not work.

  foreach (Component eachComponent in this.ComponentModel.Components)
  {
#>

	<#= eachComponent.Name #> <#= 
		string.IsNullOrEmpty(eachComponent.Kind) ? "" : "(" + eachComponent.Kind + ")" #> <#=
		eachComponent.Superclass == null ? "" : ": " + eachComponent.Superclass.Name #>
<#
	// List the links to other Components via their ports
	foreach (ComponentPort port in eachComponent.Ports)
	{
		OutPort source = port as OutPort;
		if (source != null) // a ComponentPort might be an InPort
		{
		    // List the connections from this OutPort
			foreach (Connection link in Connection.GetLinksToTargets(source))
			{
			   // Give the labels on the links, and
			   // the name of the parent Component of the target InPort.
#>
			   <#= link.SourceRoleName #> -- <#= link.TargetRoleName #> : <#= link.Target.Component.Name #>
<#		
			}
		}
	}
  }
  
	// T4Toolbox experiments
  
	SampleTemplate template = new SampleTemplate();
	template.Output.File = @"SubFolder\SampleOutput.txt";
	template.Render();
#>
<#+
    public class SampleTemplate : Template
    {
        protected override void RenderCore()
        {
            this.WriteLine("Hello, World!");
        }
    }
#>

As you can see I've took a Component project for DSL Tools, didn't make any changes, generated it, compiled, Ctrl-F5ed it and changed the L3Report.tt file to the above text.

I've got a numerous errors like the following

 

Compiling transformation: 'Microsoft.VisualStudio.TextTemplating9BB78550CDE7DB29D599014320C8A062.GeneratedTextTransformation.SampleTemplate' does not contain a definition for 'Output' and no extension method 'Output' accepting a first argument of type 'Microsoft.VisualStudio.TextTemplating9BB78550CDE7DB29D599014320C8A062.GeneratedTextTransformation.SampleTemplate' could be found (are you missing a using directive or an assembly reference?)   

Compiling transformation: 'Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation.ConvertModelRelativePathToTemplateRelativePath(string, string, string)' is inaccessible due to its protection level

Compiling transformation: 'Microsoft.VisualStudio.TextTemplating9BB78550CDE7DB29D599014320C8A062.GeneratedTextTransformation' does not contain a definition for 'AddDomainModel' and no extension method 'AddDomainModel' accepting a first argument of type 'Microsoft.VisualStudio.TextTemplating9BB78550CDE7DB29D599014320C8A062.GeneratedTextTransformation' could be found (are you missing a using directive or an assembly reference?)   

Compiling transformation: 'Microsoft.VisualStudio.TextTemplating9BB78550CDE7DB29D599014320C8A062.GeneratedTextTransformation' does not contain a definition for 'Store' and no extension method 'Store' accepting a first argument of type 'Microsoft.VisualStudio.TextTemplating9BB78550CDE7DB29D599014320C8A062.GeneratedTextTransformation' could be found (are you missing a using directive or an assembly reference?) 

Did you try to use T4Toolbox in the Debugging project of DSL Tools?

Thanks for your help

ms440

 

 

 

 

Jul 29, 2009 at 2:53 AM
Edited Jul 29, 2009 at 2:55 AM

Add the following parameter to the template directive:

inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"

Jul 29, 2009 at 5:59 AM

Thank you, Oleg for your response.

The inclusion of this attribute was exactly what was leading to the error I've started this thread with.

Here is the code with the inherits attribute:

<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension=".txt" #>
<#@ include file="T4Toolbox.tt" #>
<#@ L3 processor="L3DirectiveProcessor" requires="fileName='Sample.L3'"  #>
Report template


<#= this.ComponentModel.Name #>

<#
    // inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"
  // When you change the DSL Definition, some of the code below may not work.

  foreach (Component eachComponent in this.ComponentModel.Components)
  {
#>

    <#= eachComponent.Name #> <#=
        string.IsNullOrEmpty(eachComponent.Kind) ? "" : "(" + eachComponent.Kind + ")" #> <#=
        eachComponent.Superclass == null ? "" : ": " + eachComponent.Superclass.Name #>
<#
    // List the links to other Components via their ports
    foreach (ComponentPort port in eachComponent.Ports)
    {
        OutPort source = port as OutPort;
        if (source != null) // a ComponentPort might be an InPort
        {
            // List the connections from this OutPort
            foreach (Connection link in Connection.GetLinksToTargets(source))
            {
               // Give the labels on the links, and
               // the name of the parent Component of the target InPort.
#>
               <#= link.SourceRoleName #> -- <#= link.TargetRoleName #> : <#= link.Target.Component.Name #>
<#        
            }
        }
    }
  }
 
    // T4Toolbox experiments
 
    SampleTemplate template = new SampleTemplate();
    template.Output.File = @"SubFolder\SampleOutput.txt";
    template.Render();
#>
<#+
    public class SampleTemplate : Template
    {
        protected override void RenderCore()
        {
            this.WriteLine("Hello, World!");
        }
    }
#>

And here is the resulting diagnostics:


A processor named 'T4Toolbox.DteProcessor' could not be found for the directive named 'dte'. The transformation will not be run.  The following Exception was thrown:
System.IO.FileNotFoundException: Failed to resolve type for directive processor T4Toolbox.DteProcessor.
   at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolveDirectiveProcessor(String processorName)
   at Microsoft.VisualStudio.TextTemplating.Engine.ProcessCustomDirectives(ITextTemplatingEngineHost host, TemplateProcessingSession session, List`1 directivesToBeProcessed)    

This time it is pretty much consistent - I'm getting it after resetting the Experimental Hive regularly.

I'm stuck :(


/ms440

Jul 29, 2009 at 12:53 PM

This is caused by the missing registration of the DteProcessor in the experimental hive of Visual Studio configuration. Verify that it is registered correctly in the following registry key:

HKCU\Software\Microsoft\VisualStudio\9.0Exp\Configuration\TextTemplating\DirectiveProcessors\T4Toolbox.DteProcessor.

It should match the information in the main hive:

HKLM\Software\Microsoft\VisualStudio\9.0\TextTemplating\DirectiveProcessors\T4Toolbox.DteProcessor.

If it doesn't, I would reinstall T4 Toolbox and then reset the Visual Studio experimental hive.

Aug 31, 2009 at 9:15 AM

I had this new error after running my scaffolding for the first time in a while.

Error 1 Compiling transformation: 'Microsoft.VisualStudio.TextTemplating45220E4BAF30E9F5BA97933DF6D99EF5.GeneratedTextTransformation.Template' does not contain a definition for 'Output

Not directly related to above but figured it may have to do with an update/hot patch to some element of my setup.  I first decided to upgrade T4 toolbox to the latest from 9.1.20 and this worked!  lucky.

 

Aug 31, 2009 at 12:49 PM

@column,

Glad it worked for you. Here is a detailed write-up on how to use T4 Toolbox with DSLs: http://www.olegsych.com/2009/08/t4-tutorial-generating-code-from-dsl-models/

Oleg