Peter Goodman bio photo

Peter Goodman

A software engineer and leader living in Auckland building products and teams. Originally from Derry, Ireland.

Twitter Google+ LinkedIn Github

Here are the slides and the code for the talk on VSX, DSLs and T4 that I did in the North Shore and Auckland .Net User Groups.

Snippets

For snippets I used the Snippet Designer on Visual Studio Gallery. The code for that template is attached below.

I also talked about using Resharper Live Templates, there is some pretty good documentation here.

Macros

We talked about macros and here they are:

Create a Guid. This macro will insert a new guid at the cursor location. We mapped this to a keyboard command (Alt+G) with the Tools->Options->Keyboard menu in VS.

Sub Create_GUID()
    DTE.ActiveDocument.Selection.Text = System.Guid.NewGuid().ToString("D").ToUpper()
End Sub

 

Copy Files to Drop. This macro will copy the output of the selected project to a drop folder.

Sub CopyFilesToDrop()
    For Each selectedItem As SelectedItem In DTE.SelectedItems
        If (selectedItem.Project IsNot Nothing) Then
            Dim project As Project = CType(selectedItem.Project, Project)
            Dim fullProjectPath As String = project.Properties.Item("FullPath").Value.ToString()
            Dim fileName As String = project.Properties.Item("OutputFilename").Value
            Dim outputPath As String = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value
            Dim outputFile As String = System.IO.Path.Combine(fullProjectPath, outputPath, fileName)
            System.IO.File.Copy(outputFile, System.IO.Path.Combine("c:\drop", fileName), True)
        End If
    Next
End Sub

 

Custom Designer

One of the things that became apparent when I was preparing this talk was how many designers in Visual Studio are simply a designer over an XML file, DSLs, Resx designer, project properties. A good sample for creating your own is the Designer over XML sample on Visual Studio code gallery.

DSL Tools

When we looked at DSL Tools for Visual Studio we simply took the Class Designer example that ships once you have installed the Visual Studio SDK and the Visualization and Modeling SDK. If you want to save yourself some time look at getting the awesome book written by the team that made the tools.

T4

We then created a tt file that would generate viewmodel code that implemented NotifyPropertyChanged form the class designer dsl implementation. THe whole DSL project is attached below. Simply install the VS SDK and the Visualization and Modeling SDK, open the project, hit the transform all templates button in solution explorer and hit CTRL+F5. This will open the debugging project where you can see the output of the ViewModels.tt file. Right click the file and run the custom tool to regenerate the output.

 

Download the Slides

Download the snippet