2011-08-25 97 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