Inside F#

Brian's thoughts on F# and .NET

Archive for August, 2008

Welcome to the F# CTP project system: project property pages

Posted by Brian on August 30, 2008

(Link reminders: download the new F# September 2008 CTP Release, and check out the new F# Developer Center.)

One of the goals of the F# CTP release is to make F# easier to approach for developers already familiar with Visual Studio.  If you have used prior releases of F#, while there were project "property pages", they were rather different from the property pages you’d encounter when using other Visual Studio languages, like C# or Visual Basic.  The new project property pages in the CTP release of F# enjoy the same look-and-feel as those from other Visual Studio languages.

The project property pages can be accessed by right-clicking on the project and choosing "Properties":

ProjectPropertyPage1

There are five tabs with various useful project-level settings.  For example, if I want to change the name of the assembly that gets built, I can do so on the "Application" tab:

ProjectPropertyPage2

And if I want to specify command-line arguments, I can do it via the "Debug" tab:

ProjectPropertyPage3

If I run the short program illustrated in the next screenshot, I can tell that these settings have taken effect; "Brian" was passed as a command-line argument, and the active window title shows that the application is named "Hello.exe":

ProjectPropertyPageRunning

Incidentally, this tiny example demonstrates how you can use the F# EntryPointAttribute to mark a function as the "main" of the application, which receives the command line arguments as an array of strings and returns an integer return code.  (Those who are curious can read more about EntryPoint in the F# manual.)

More on other new features of the CTP coming soon!

Posted in Uncategorized | Leave a Comment »

Welcome to the F# CTP project system: project templates

Posted by Brian on August 29, 2008

As you may have already heard, the F# CTP has been released!  Here is the release announcement.  I’ll continue describing the F# project system, but now that the CTP is out, you can follow along on your own machine, rather than just having to soak in the teaser screenshots I posted in prior blog entries.  :)

Today’s blog entry describes the F# project templates.  Whereas the prior releases of F# came with only one project template, the CTP release has three.  Inside Visual Studio, do a "File>New>Project" and select the "Visual F#" node to see this:

ProjectTemplates

(Aside: if you’re like me, and you still have a prior install of F# on your machine, the old project template will still appear in "Other Project Types > F# Projects" under "Project types".  So if you’re only seeing the old template after installing the CTP, make sure that you have selected the new "Visual F#" node and not the old "F# Projects" node:

ProjectTemplateKinds

Also, note that my screenshots today are from my computer at home, which has only the free Visual Studio 2008 Shell installed.  If you have a full version of Visual Studio, then you’ll also see other project types, such as "Visual C#", in the "New Project" dialog.)

There are three types of F# project templates in the F# CTP release; I’ll describe each in turn.

F# Application

The "F# Application" template is used to build an executable program (EXE).  It will start you with a single source code file, Program.fs.  Type in some code, and you can just build and run:

Application

F# Library

The "F# Library" template is used to build a library (DLL), which you might later reference from another application (and that application might be written in F#, or C#, or whatever – see my previous blog entry on project references).  The "F# Library" template starts you off with two files: Module1.fs, an F# source code file that will be compiled into the library DLL, and Script.fsx, an F# script file which is not compiled into the library DLL.  I’ll talk more about F# script files in a future blog entry; briefly, scripts are one easy way to associate extra functionality (such as unit tests) with a particular project, without that functionality being compiled into the project.

Library

F# Tutorial

The "F# Tutorial" template’s main purpose is to demonstrate some of the main features and syntax of the F# language with some sample code.  If you are relatively new to the language, reading the code in Tutorial.fs is one way to get a quick introduction to F#.  It’s also useful if you need a quick refresher to remember the syntax for a particular feature.  For instance, if I forget how to author a class that implements an interface, I can scroll down through the tutorial code and find:

Tutorial

There’s lots more to talk about with the new project system… more blog entries coming soon!  (If you have questions in the meantime, feel free to post them in comments on this blog, or to use the forums on the hub.)

Posted in Uncategorized | 4 Comments »

Sneak peeks into the F# project system, part three

Posted by Brian on August 3, 2008

There will be a number of new F# IDE features in the upcoming CTP release.  One that you may have used with other Visual Studio languages is "Add As Link".

Add As Link

By default, when you add an existing item that lives outside of the current project directory, Visual Studio will copy the file to the current project directory. 

image

If I select a file from some other directory (for instance, from a C# project directory)…

image

Then a copy of that file (here, App.config) gets added to the project:

image

You can tell it’s a copy by looking on disk:

image

which shows the new file has been copied to the F# project directory:

image

However, if we start over, we could instead choose to add the file as a link (notice the drop-down in the bottom-right corner of the screenshot):

image

Then a linked file is added to the project:

image

Note the little arrow sub-glyph in the icon that shows that the file is a link.  It has not been copied to the project directory:

image

If you are familiar with msbuild, then you may recognize the representation in the .fsproj project file:

image

Whereas the "Include=" bit describes the physical location of the file, the optional "<Link>" tag is used by linked items to describe how to project linked files into the solution explorer view inside Visual Studio.  This is no different than how things work in C#.

 

Also in the upcoming CTP release, we’ll also support a better "ordering experience" from inside the solution explorer in the IDE.

Move Up and Move Down

If you want to change the ordering of files, you can do it via the right-click menu in the solution explorer.  Say I have

image

and I decide that Program.fs needs to be moved before File2.fs.  I can right click on Program.fs…

image

and select "Move Up", and…

image

now Program appears above File2.  There will be a key-binding (probably Alt-Up/Alt-Down) associated with the Move Up and Move Down commands.

Add Above and Add Below

If I am adding a new file to a project, and I want it to appear in the ‘middle’ somewhere, I could right-click on the project, do "Add New Item…", have the item get added to the bottom, and then use a series of Move Up commands to get the file into the right spot.  Or, I could use this new menu command:

image

so that the new file appears above or below an existing item.  Here I’ve added a new item File3.fs above Program.fs:

image

These new commands make it much easier to manage the file order in an F# project.

Posted in Uncategorized | 1 Comment »