Visual Model For F# – Installation

Installation and start-up

Plugin to Microsoft Visual Studio 2010 is installed by double-clicking on the package with the .VSIX extension, and then follow the instructions. In the case of this project a file is named BielastyAdam.VisualModelForFSharp.DslPackage. Pack looks like Figure 1 below.

Plugin VisualModelForFSharp for Microsoft Visual Studio 2010

Figure 1:  Plugin VisualModelForFSharp for Microsoft Visual Studio 2010

The package will be distributed via the Visual Studio Gallery website. Then it will be available to other users via the Extension Manager, which is built-in the tool for Microsoft Visual Studio 2010 that allows you to install plugins. Alternatively, the plugin can be shared on any web page. Users have to download and install it manually.

In the Extension Manager the plugin can be accessed by selecting the tools menu:
Tools->Extension Manager…

Extension Manager window is shown in Figure 2 below. Here you can find the installed plug-ins and see their status. Using the Extension Manager, you can search other plug-ins from Visual Studio Gallery online.

Okno Extension ManagerFigure 2: Window Extension Manager

If you can see the plug-in Visual Model For F #, it means that the installation was successful.

To use the functionality offered by this addition, you must create a new F # project. This is shown in Figure 3. To do this, click on the toolbar in the following order.
File-> New-> Project …

You will see the following window. Please select the application F#.

Okno z wyborem projektu F#Figure 3: Window to the choice of project F#

The next step is to create a sister project to the last. To do this properly you need to select the main root of the tree in the Solution Explorer. Click the right mouse button on the branch
Add-> New Project …

and the best is to choose the empty Empty Project project, as it is shown in Figure 4 below.

Okno z wyborem projektu C#Figure 4: Window to the choice of a C#
It is necessary to choose a C# or VisualBasic, because for these projects, you can create files with the extension of Text Templates. Tt, for which you can later generate the source code.

Our main solution should look now like on Figure 5. We have the F# project, and selected project C#. In the latter models will be created and transformed .tt files from the source code.

Główna solucja w Visual Studio 2010

Figure 5: The main solution in Visual Studio 2010

It should be now added to the project files so that you can model the functional programs and generate source code. The files responsible for these things add up automatically when you select a project
Add-> New Item …

when you hit the right button on the C# project. You have to do so, because of C# is available to transform text files with .tt extension.

The following window (Fig. 6) shows that among the options we have to choose the Visual Model For F #. Select this item, enter the name in the Name field, such as Model1.vmffs, and click Add to add.

Okno z wyborem pliku modeluFigure 6: Window to the choice of the model file

After completing the previous steps our solution tree should look like Figure 7 below. New files have been added to the project: Model1.vmffs file is the most important file that can be opened with a visual editor. Just click on it twice. Model1.vmffs.diagram text file stores the character model. Another file is Model1.tt, i.e. to transform a text file. The result transformed model is shown as Model1.fs file, which is a source code file in F#.

Note: If Model1.tt file does not appear automatically in the tree with the project, you must create it manually. To do this, right-click on the name of the project such as OurModelProject and select the new .tt file (Text Template). Then add the following code:

<#@ output extension=".fs" #>
<#@ VisualModelForFSharp processor="VisualModelForFSharpDirectiveProcessor" requires="fileName='$fileinputname$.vmffs'" #>
<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" #>
//plugin: Visual Model For F#
//author: Adam Bielasty
//website: www.bielasty.pl

<#= this.RootModel.GenerateCode() #>

Listing 1: TT Template

In place of $fileinputname$.vmffs insert the name of the file containing the model, e.g. Model1.vmffs.

Główna solucja po dodaniu pliku modelu

Figure 7: The main solution after adding a model file

If you want to have something visible in the Model1.fs file, always after finishing the model, click on the Transform All Templates button shown in Figure 8 below. After this action all the files with the .tt extension will be transformed according to their definition.

Przycisk do uruchomienia transformacji wszystkich plików z rozszerzeniem .tt

Figure 8: Button to start the transformation of all files with the .tt extension

Finally, we copy and paste the following result of transformation or just paste the .fs file to the project application from F#. In this way we can create multiple files with source code F #, from which we can use F# in the project.

The following Figure 9 is presented in the main window of Microsoft Visual Studio 2010 during the functional modeling. The left part is a set of components that can be dragged and dropped to the main space.

Główne okno VS 2010 podczas modelowaniaFigure 9: Main window of VS 2010 during the modeling

adamex

About Adam Bielasty

.NET Software Developer

Leave a Reply

Your email address will not be published. Required fields are marked *


6 × 6 =

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>