Assembly Information for F# Console Applications

Right on the heels of my last post about an AssemblyInfo.fs file for F# Libraries (DLLs), we can do the same thing for F# console applications with a slight modification.

The default F# console application contains a single Program.fs source file. By default, this puts everything in that file into a module named “Program”.

The entry point of an F# console application is typically the top-most code in the last .fs file of the project.  This leads to the standard F# programming pattern of the last file in the project (typically Program.fs) containing something along the lines of:

let main () =

  …

 

main ()

Now, to add all of the assembly metadata to the project, we need to attribute the “main ()” function call with all of the attributes.  We can’t use the “unit” operator “()” like we did in the F# Library case, since our console application actually does have an entry point that we care about.

We can accomplish this by moving the “main ()” line to the AssemblyInfo.fs file, requiring us to fully-qualify it to “Program.main ()” since it resides in the Program module.

If we add the AssemblyInfo.fs file from the previous post, it must go last, for example:

image

Now, in Program.fs we only have:

let main () =

  …

And at the end of AssemblyInfo.fs we have:

[<assembly: AssemblyVersion("1.0.0.0")>]

[<assembly: AssemblyFileVersion("1.0.0.0")>]

Program.main ()

Just like in the library case, it would be nice if the default F# console application template included both Program.fs and AssemblyInfo.fs and included a definition for “main” to avoid any confusion as to the entry point of the application.

Hope that helps!


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply