F# Project and Item Templates (revised)

Over the past few months I have posted up a few Project and Item Templates for F#. Here is a quick summary of those templates.

The Project Templates include:

  • WPF Project
  • WinForms Application
  • Console Application
  • Windows Service
  • F# Class Library

These Project Templates install the following Item Templates:

  • Class
  • Disposable Class
  • Interface
  • Windows Form

There is also a Item Template for:

  • Assembly Info File

If one desires all these elements can be installed separately or with a single extension from:

https://visualstudiogallery.msdn.microsoft.com/7221b01d-89b2-4102-bbed-da8ae319a6d6

Here is a brief description of the Project and Items Templates.

WPF Application

This template is for a basic F# Windows Presentation Foundation (WPF) project. This template can be found on the Visual Studio Gallery:

https://visualstudiogallery.msdn.microsoft.com/33dab4ce-62b8-419e-8072-92bc88556f78

When the template is installed you get the following template added to your F# folder when creating a new F# project:

image_thumb[1]_thumb

This template that defines the following project elements:

  • MainWindow.fs: This is a module that has a single initControls() function that take in a Window element. The module provides a TODO tag showing the location for processing window elements and hooking up window events.
  • MainWindow.xaml: The XAML for the main window of the application.
  • App.xaml: XAML used for starting up the MainWindow window.
  • Program.fs: This controls the displaying of the window and ensures the STA Thread is used.

The MainWindow.fs file provides the structure for processing the window elements.

Windows Console Application

The template can be found on the Visual Studio Gallery:

https://visualstudiogallery.msdn.microsoft.com/031891a9-06c3-47db-9c7d-8c9d4a32546a

When the template is installed you get the following template added to your F# folder when creating a new F# project:

7510.image_17A196C0

The Project Template creates a Windows Console Application with the following components:

  • Program.fs: The application entry point defined
  • Arguments.fs: A simple command line parser placing all arguments into a dictionary
  • MyConsole.fs: A separate module for the custom console application code

Assembly Information File Item Template

The template can be found on the Visual Studio Gallery at:

https://visualstudiogallery.msdn.microsoft.com/06bc7a47-be14-42b9-a8cb-86031922ff83

This extension creates a file called AssemblyInfo.fs, that contains the standard assembly definitions usually associated with other programming languages.

Once this assembly information file is included in your project, you will be able to see the usual property definitions associated with the assembly:

assembly

Class Library Project Template

This template creates a Windows Library with a simple class definition. The template can be found on the Visual Studio Gallery:

https://visualstudiogallery.msdn.microsoft.com/a3f39bd9-9fd2-4465-a931-2163758a1447

When the template is installed you get the following template added to your F# folder when creating a new F# project:

class

This template also defines several Item Templates for creating the following project items:

  • F# Class – The definition of a simple F# class
  • F# Interface – The definition of a simple F# interface
  • F# Disposable Class – The definition of a F# class that implements IDisposable

Windows Service Project Template

This template that provides the elements for the creation windows service in F#. The template can be found on the Visual Studio Gallery:

https://visualstudiogallery.msdn.microsoft.com/1f2ee1da-e87f-4863-b98e-d8b7b63d2253

When the template is installed you get the following template added to your F# folder when creating a new F# project:

service

This template provides several projects elements:

  • A MyService.fs and Program.fs source file providing the service elements
  • An Installer.fs source file enabling the service to be installed using the installutil tool
  • A command file for installing and un-installing the service

The MyService.fs source file provides the implementation of the service. The template code provides the structure for the OnStart and OnStop methods and shows how an EventLog can be created and referenced:

WinForms Project Template

This template is for an F# WinForms application. This template can be found on the Visual Studio Gallery:

https://visualstudiogallery.msdn.microsoft.com/eba78049-a17e-4868-9ead-065da1421052

When the template is installed you get the following template added to your F# folder when creating a new F# project:

winforms

This template that defines two project elements:

  • MainForm.fs: This is a class, derived from Form, which the application will display. The template provides some TODO tags showing the user the locations for inserting form controls.
  • Program.fs: This controls the displaying of the form and ensures the STA Thread is used.

The MainForm.fs file provides the structure for a type derived from Form. It demonstrates the Form definition providing placeholders for adding forms to the control and hooking up both form and control events.