Ask a questionAsk a question
 

AnswerPreprocessed Text Templates and DSLs in VS2010

  • Monday, September 28, 2009 1:47 PMFilipe Romano Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I created a preprocessed text template to generate code from a DSL model in VS2010 Beta 1. I noticed that the Initialize() method is loading the model using an absolute path in the generated code. Are there any plans to solve this issue, using either of the following alternatives?

    1. Exposing a ModelPath property in the generated class that can be defined before calling Initialize().
    2. Generating an overload to the Initialize method that takes the model path as an argument.

    Thanks.

Answers

  • Sunday, October 11, 2009 9:03 PMGarethJonesMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Filipe,

    The code that's creating this fragment in the Initialize method is the model directive processor and the absolute path is coming from the absolute path in the template itself.
    You can modify the generated directive processor to do something else either by overriding generated methods or by changing the template used to generate the directive processor.

    We don't have any plans to modify this in the general DSL code as we're not focused on PreProcessed templates other than as a mechanism to allow T4's to run inside arbitrary .Net applications.   

    As you can only really use DSLs in applications that work with (or close to Visual Studio) this isn't a high priority for us.

    Gareth Jones - Architect - DSL Tools & Visual Studio eXtensibility [MSFT]

All Replies

  • Sunday, October 11, 2009 9:03 PMGarethJonesMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Filipe,

    The code that's creating this fragment in the Initialize method is the model directive processor and the absolute path is coming from the absolute path in the template itself.
    You can modify the generated directive processor to do something else either by overriding generated methods or by changing the template used to generate the directive processor.

    We don't have any plans to modify this in the general DSL code as we're not focused on PreProcessed templates other than as a mechanism to allow T4's to run inside arbitrary .Net applications.   

    As you can only really use DSLs in applications that work with (or close to Visual Studio) this isn't a high priority for us.

    Gareth Jones - Architect - DSL Tools & Visual Studio eXtensibility [MSFT]
  • Tuesday, November 03, 2009 11:38 PMFilipe Romano Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I worked around this issue by adding an overload to the Initialize method in a partial class, but I did that by copying the entire method code (see details here ).
    What could work would be to add a public property that holds the template path, and generating the Initialize method like this:

    if (string.IsNullOrEmpty(
    this.ModelPath
    ))
    {
    this
    .examplemodelValue = Company.Language1.Language1SerializationHelper.Instance.LoadModel(serializationResult, this .Store, this.ModelPath , null , null , null );
    }

    Then it would be possible to call the template like this:

     DslTextTemplate t = new
     DslTextTemplate();
    t.ModelPath = "C:\\Users\\MyUser\\Documents\\Visual Studio 10\\Projects\\Language1\\Language1\\Debugging \\Sample.mydsl1" ;
    t.Initialize();
    this .Write(t.TransformText());