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.

