F# and .Net versions
I'm writing a program in F# at the moment, which I specified in the Visual Studio project setup to target .Net 3.5, this being the highest offered, on the theory that I might as well get the best available.
Then I tried just now running the compiled program on an XP box, not expecting it to work, but just to see what would happen. Unsurprisingly I just got an error message demanding an appropriate version of the framework, but surprisingly it wasn't 3.5 it demanded, but 2.0.50727.
An additional puzzle is the version of MSBuild I'm using to compile the release version of the program, which I found in the framework 3.5 directory but claims to be framework 2.0 and build engine 3.5. I just guessed it was the right version of MSBuild to use because it seemed to correspond with the highest framework version F# seems to be able to target, but should I be using a different version? Anyone have any idea what's going on?
C:\Windows>dir/s msbuild.exe
Volume in drive C is OS
Volume Serial Number is 0422-C2D0
Directory of C:\Windows\Microsoft.NET\Framework\v2.0.50727
27/07/2008 19:03 69,632 MSBuild.exe
1 File(s) 69,632 bytes
Directory of C:\Windows\Microsoft.NET\Framework\v3.5
29/07/2008 23:40 91,136 MSBuild.exe
1 File(s) 91,136 bytes
Directory of C:\Windows\Microsoft.NET\Framework\v4.0.30319
18/03/2010 16:47 132,944 MSBuild.exe
1 File(s) 132,944 bytes
Directory of C:\Windows\winsxs\x86_msbuild_b03f5f7f11d50开发者_如何学Ca3a_6.0.6000.16386_none_815e96e1b0e084be
20/10/2006 02:14 69,632 MSBuild.exe
1 File(s) 69,632 bytes
Directory of C:\Windows\winsxs\x86_msbuild_b03f5f7f11d50a3a_6.0.6000.16720_none_81591d45b0e55432
27/07/2008 19:00 69,632 MSBuild.exe
1 File(s) 69,632 bytes
Directory of C:\Windows\winsxs\x86_msbuild_b03f5f7f11d50a3a_6.0.6000.20883_none_6a9133e9ca879925
27/07/2008 18:55 69,632 MSBuild.exe
1 File(s) 69,632 bytes
C:\Windows>cd Microsoft.NET\Framework\v3.5
C:\Windows\Microsoft.NET\Framework\v3.5>msbuild /ver
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3053]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
3.5.30729.1
It is because .NET versions are a bit confusing. The languages, the runtime and the library itself all have separate version numbers. .NET 3.5 runs on version 2.0 of the runtime and is really just a collection of additional assemblies. If you don't reference any of the new assemblies, you application is essentially a 2.0 application as the core for .NET 3.5 is 2.0.
Fortunately with the latest release the library, the runtime and C# are all called version 4.
The wiki article on .NET has more details on this.
Regarding F# more specifically, there are currently two versions available:
Version that comes with Visual Studio 2010 - this is the latest you can get and is designed for .NET 4.0 (which is a completely new version of the runtime as Brian points out). This version of F# relies on some features that are available in .NET 4.0 libraries, so F# programs compiled for .NET 4.0 won't work on .NET 2.0.
Version for Visual Studio 2008 (also called CTP). This version is producing assemblies compatible with the 2.0 runtime (which is also used by .NET 3.0 and 3.5). If you use only .NET 2.0 assemblies, then your application will work on .NET 2.0, but if you use WPF (.NET 3.0) or LINQ (.NET 3.5) your application will require newer .NET.
In any case, F# applications also need to be distributed with the FSharp.Core.dll
(for .NET 4.0 or 2.0), which is an F# runtime (containing some features that are needed by F# programs, but aren't available in .NET, regardless of the version).
精彩评论