4.2 MetaEdit+ extension for Visual Studio
While the C# generator for the Watch Example provides
entry-level integration with Visual Studio by generating the required project
definitions and other additional files, it is recommended to use an additional
free Visual Studio extension to take the full advantage of the Visual Studio and
MetaEdit+ integration. There are several advantages of using the
extension:
| One-click
access to your MetaEdit+ repository from Visual Studio
|
| Live
tree view in Visual Studio of all your MetaEdit+ models
|
| Double-click
to open and edit MetaEdit+ models from Visual Studio
|
| Autobuild:
generate code from MetaEdit+ models, import into a Visual Studio solution, build
and run
|
| Trace
and debug on both the code and model levels simultaneously
|
The MetaEdit+ extension for Visual Studio
requires a Workbench or API version of MetaEdit+, and Visual Studio Ultimate,
Professional, Enterprise or Community (the supported versions at the time of
writing are VS 2010, 2012, 2013 and 2015, with Community allowing extensions
only from 2013). It can be downloaded for free from
http://visualstudiogallery.msdn.microsoft.com.
The source code and documentation for the extension is available at
http://graphbrowser.codeplex.com.
To install the extension, start Visual Studio and select
Tools | Extensions and Updates... from the menu bar (or
Tools |
Extension Manager... in Visual Studio 2010). This will open the extension
management tool, as shown in
Figure
4-1.
Figure 4-1. Visual Studio extensions and updates
By
default, the tool shows the currently installed extensions and updates. To find
the MetaEdit+ extensions, select
Online (or
Online Gallery in
Visual Studio 2010) and enter “MetaEdit+ extension” as the search
string into the search field in the top-right corner of the window. Once the
extension has been found and appears in the list (as in
Figure 4-2), press the
Download
button and follow the instructions to complete the extension
installation.
Figure 4-2. Finding and downloading Visual Studio extension
Start
the extension in Visual Studio by selecting
View | More Windows | Graph
Browser. The extension will try to start MetaEdit+ from its expected default
location. However, if MetaEdit+ is installed elsewhere, the error dialog shown
in
Figure 4-3 will appear. Should this
happen, you can set the required paths for MetaEdit+ by clicking the
Open the
Launch Parameter Window button in the toolbar (the one with the gear icon)
and entering the correct values in dialog that opens.
Figure 4-3. ‘No connection to MetaEdit+ API’ error dialog.
When
the extension connects to MetaEdit+, it will populate the Graph Browser pane
with a list of the graphs available in MetaEdit+ at the time (as shown in
Figure 4-4).
Figure 4-4. Visual Studio extension Graph Browser.
The
following operations are available in the Graph Browser pane:
| Run
‘Autobuild’ generator for selected
graph |
| Run
selected generator for selected
graph |
| Open
selected graph in
MetaEdit+ |
| Edit
properties of the selected
graph |
| Create
new
graph |
| Update
graph
list |
| Show/hide
types |
| Setting
launch parameters |
All communication between
the extension and MetaEdit+ is carried out via the MetaEdit+ API. Hence, all
model editing and code generation is carried out natively in MetaEdit+ while the
generated code is loaded into, built and executed in Visual Studio. To try this
out, select ‘WatchModels’ graph in the Graph Browser pane and then
Edit Graph Properties from its popup menu. This will open the usual
property dialog in MetaEdit+. Set ‘C#: API’ as the
Generation
target platform, OK the dialog and select
Run Autobuild from the
‘WatchModels’ popup menu in the Graph Browser pane to launch the
code generation. After the code is generated and compiled, the test environment
will be launched and visual debugging activated (as shown
Figure 4-5).
Figure 4-5. Using the Visual Studio extension