以下F#代码与F#3.0 fsc.exe编译得非常好 但未能执行。在交互模式(fsi.exe)中,一切正常。
我收到错误信息。
“参考装配 'C:_src_ \ compilation_sql \ FSharp.Data.TypeProviders.dll'有程序集 级别属性 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' 但是在执行时没有找到公共类型提供程序类。
为什么?
程序在current.fs
文件中写入一段代码并调用Fsharp.compiler.service
将脚本编译成DLL程序集
从程序的编译版本执行时,让errors1,exitCode1 = scs.Compile([| “FSC”; “ - R:System.Core.dll”; “ - R:System.Collections.Immutable.dll”; “ - R:System.Reflection.Metadata.dll”;“ - R:FSharp.Compiler.dll “;” - R:FSharp.Compiler.CodeDom.dll “;” - R:System.Data.Linq.dll “;” - R:FSharp.Data.DesignTime.dll “;” - R:FSharp.Compiler.Service .DLL” ; “ - R:FSharp.Data.TypeProviders.dll”; “O”; FN3; “-一个”; fn2 |])
失败。
我使用命令行编译代码:
fsc.exe -r:System.Core.dll -r:System.Collections.Immutable.dll -r:System.Reflection.Metadata.dll -r:FSharp.Compiler.dll -r:FSharp.Compiler.CodeDom.dll -r:System.Data.Linq.dll -r:FSharp.Data.TypeProviders.dll -r :FSharp.Compiler.Service.dll compilation_sql.fs
我非常简单地执行编译的程序:
compilation_sql.exe
System.IO.Directory.SetCurrentDirectory (__SOURCE_DIRECTORY__)
printfn "repertoire d execution : %s" __SOURCE_DIRECTORY__
#if INTERACTIVE
#r "System.Data.Linq.dll"
#r "FSharp.Compiler.dll"
#r "FSharp.Compiler.CodeDom.dll"
#r "FSharp.Data.TypeProviders.dll"
#r "FSharp.Compiler.Service.dll"
#r "System.Collections.Immutable.dll"
#r "System.Reflection.Metadata.dll"
#endif
open System
open System.IO
open System.Collections.Immutable
open System.Reflection.Metadata
open Microsoft.FSharp.Compiler.SimpleSourceCodeServices
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq
open System.Data.Linq.SqlClient
// let fn = Path.GetTempFileName()
let fn = sprintf "%s\\current.fs" __SOURCE_DIRECTORY__
printfn "Fichier à Compiler %s" fn
let fn2 = Path.ChangeExtension(fn, ".fs")
let fn3 = Path.ChangeExtension(fn, ".dll")
let script = """
#if INTERACTIVE
#r "System.Data.dll"
#r "FSharp.Data.TypeProviders.dll"
#r "System.Data.Linq.dll"
#else
namespace ODDO
#endif
open System
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq
open System.Data.Linq.SqlClient
module SQL=
[<Literal>]
let sourceConnectionString = @"Data Source=ZDATLMDL6\Z_MUT_3; Initial Catalog=DB_FXO; Integrated Security=True;"
type dbSchema = SqlDataConnection<sourceConnectionString>
let db = dbSchema.GetDataContext()
// Enable the logging of database activity to the console.
db.DataContext.Log <- System.Console.Out
let query1 =
query {
for row in db.COMPTEUR do
select row
}
let display (res : System.Linq.IQueryable<dbSchema.ServiceTypes.COMPTEUR>) =
printfn "Resultat :"
res |> Seq.iter (fun row -> printfn "%d %s %s " row.ID row.CODE row.LIBELLE )
printfn "Fin de table"
()
"""
File.WriteAllText(fn2, script)
let scs = SimpleSourceCodeServices()
//let errors1, exitCode1 = scs.Compile([| "fsc";"-r:System.Core.dll";"-r:FSharp.Compiler.dll";"-r:FSharp.Compiler.CodeDom.dll";"-r:System.Data.Linq.dll";"-r:FSharp.Data.TypeProviders.dll";"-r:FSharp.Compiler.Service.dll"; "-o"; fn3; "-a"; fn2 |])
let errors1, exitCode1 = scs.Compile([| "fsc";"-r:System.Core.dll";"-r:System.Collections.Immutable.dll";"-r:System.Reflection.Metadata.dll";"-r:FSharp.Compiler.dll";"-r:FSharp.Compiler.CodeDom.dll";"-r:System.Data.Linq.dll";"-r:FSharp.Data.DesignTime.dll";"-r:FSharp.Compiler.Service.dll" ;"-r:FSharp.Data.TypeProviders.dll"; "-o"; fn3; "-a"; fn2 |])
printfn "Nombre erreurs compilation : %d" errors1.Length
for i in 0..errors1.Length - 1 do
let mutable werror = Array.get errors1 i
// printfn "%s %d %s %d " werror.get_FileName() werror.get_ErrorNumber() werror.get_Message() werror.get_StartLine()
printfn "Fichier : %s ErrorNumber : %d Message :%s" werror.FileName werror.ErrorNumber werror.Message
我是F#的新手,可能对装配知之甚少,但这让我很愚蠢。 任何人都可以给出任何提示吗?