2011-08-18 86 views
4

如果服務器上沒有安裝f#代碼(共享服務器),是否可以在服務器上運行f#代碼?我的意思是也許我可以上傳和參考所有必要的程序集? f# download place包含「其他cli實現」的zip - 也許有人有simillar問題?在服務器上運行f#代碼,即使沒有安裝f#

編輯更多的上下文:其實我使用c#編譯和運行f#程序。所以我打電話

using (CodeDomProvider provider = new Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider()) 
{ 
    cr = provider.CompileAssemblyFromSource(cp, new string[] { data.Program }); 
} 

現在在我的機器上一切都很好。我已經包含了FSharp.Core.dll(版本4)以及FSharp.Compiler.CodeDom(版本2)。一切都在本地複製。在服務器我得到這個錯誤:

Could not load file or assembly 'FSharp.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
    at Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider.CreateCompiler() 
    at System.CodeDom.Compiler.CodeDomProvider.CreateCompilerHelper() 
    at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)... 

EDIT2: 所以其實我想未安裝F#的服務器上編譯 F#代碼。這是我必須做的:

1. put FSharp.Compiler.CodeDom.dll (version 2 as there is now newer now) and FSharp.Core.dll version 2 in bin directory. 
2. create new directory in bin directory and put there this: 
-FSharp.Compiler.dll (version 4) 
-FSharp.Core (.dll, .xml, .sigdata, .optdata) (version 4) 
-Fsc.exe - f# compiler 
3. From code set process' FSHARP_BIN environment variable to point to above directory: 
System.Environment.SetEnvironmentVariable("FSHARP_BIN", Utils.RootFolder + @"bin\comilersstuff"); 

這樣編譯成功,如果你想運行它,你就不得不把Fsharp.Core.dll在同一目錄(4節)。作爲編譯的F#程序。

回答

8

當然 - 只需將FSharp-Dll複製到您的項目中或使用--standalone編譯器選項即可。當然你需要在你的服務器上安裝.net(4.0/3.5/2.0,取決於你的F#版本)框架。

最簡單的方法做的第一件:使用引用的「複製本地」設置 - DLL將被您的.exe旁邊bin文件夾放到/ .DLL(或徘徊無論你讓你的輸出去): enter image description here

+1

'FSharp.Core.dll'是可重新發布的,因此您可以將它部署在您的應用程序旁邊,這通常是最容易做的事情。 (您也可以將安裝程序鏈接到應用程序的安裝程序,另請參閱http://msdn.microsoft.com/en-us/library/ee241127.aspx)。 – Brian

+1

標記爲最初問題的答案 – ren