Implementing a VS2005 Macro for automating transformation and exporting of outputs from DSL templates

For those who are working with Domain Specific Languages Designers, there is on recurring two step task that should be automated: Tranforming and exporting the various templates ouputs to the proper locations in our working project.

To do so we can implement a simple macro that does the job for us.

Basically we need to create a method that call one command that transform all the templates in the current project:

DTE.ExecuteCommand(“TextTransformation.TransformAllTemplates”)

and then call a set of commands to copy the templates ouput to the desired directory. Here is a sample of what I said:

DTE.ExecuteCommand(“Tools.Shell”, “cmd /c copy /Y “”” + GetOriginPath() + “BusinessEntities.cs” + “””  “”” + BusinessEntitiesDestinationFile + “”””)

where GetOriginPath()  is defined as:

Private Function GetOriginPath() As String
      Dim lastIndex As Integer = InStrRev(DTE.Solution.FullName, “\”)
      Return Left(DTE.Solution.FullName, lastIndex) & “GeneratedCode\”
End Function

To learn how to assign a macro to a toolbar button check out this site.

To learn how to Edit and Programmatically Create Macros check out this site.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: