2011-08-25 66 views
1

我在F#/ WPF编程中发现了some good post,但它似乎并没有教会如何编译/构建代码以使F#/ WPF中的二进制文件成为可能。编译F#/ WPF代码

我使用什么命令/工具将此代码构建/编译为执行二进制文件?只是运行fscfsi似乎没有工作。

#light 
#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0" 
#r @"WindowsBase.dll" 
#r @"PresentationCore.dll" 
#r @"PresentationFramework.dll" 

open System 
open System.Windows 

(* From Chap 1 - SayHello.cs *) 

let win = new Window() 
win.Title <- "Say Hello" 
win.Show() 

#if COMPILED 
[<STAThread()>] 
do 
    let app = new Application() in  
    app.Run() |> ignore 
#endif 

回答

5

如果要使用fsc编译代码,则需要删除#I#r命令,并改用编译器命令行参数。 #light命令不再需要,所以你可以删除前5行。除了#r引用,我也不得不加入System.Xaml.dll(这是.NET 4的可能新)

然后你可以使用类似编译:在fsi.exe

fsc.exe -r:WindowsBase.dll -r:PresentationCore.dll -r:System.Xaml.dll 
     -r:PresentationFramework.dll --target:winexe Main.fs 

运行代码应该工作就好了(添加#r "System.Xaml.dll"后)。只需复制代码并将其粘贴到F#Interactive(在控制台或Visual Studio IDE中运行)即可。

1

运行fsc应该可以工作。您需要将--target:winexe命令行参数传递给fsc.exe。

有关更多信息,请参阅F# Compiler Options