我正在尝试在Windows上使用FSharp.Data.SqlClient
c:\...> dotnet new console -lang f# -o test5
c:\...> cd test5现在将<Import Project="fsc.props" />添加到test5.fsproj,并从https://raw.githubusercontent.com/fsprojects/FSharp.TypeProviders.SDK/master/fsc.props添加fsc.props。然后
c:\...\test5> dotnet add package FSharp.Data.SqlClient并按如下方式编辑Program.fs:
open FSharp.Data
open FSharp.Data.SqlClient
[<Literal>]
let connectionString =
@"Data Source=.\SQL14X64;Initial Catalog=test;User=sa;Password=***"
[<EntryPoint>]
let main argv =
use cmd = new SqlCommandProvider<"
SELECT 1
" , connectionString>(connectionString)
0正在尝试编译它:
c:\...\test5> dotnet build有错误:
The type 'SqlCommand' is required here and is unavailable.
You must add a reference to assembly 'System.Data.SqlClient, Version=0.0.0.0, ...好的,安装System.Data.SqlClient:
c:\...\test5> dotnet add package System.Data.SqlClient有错误:
The type 'SqlCommand' is required here and is unavailable.
You must add a reference to assembly 'System.Data.SqlClient, Version=4.2.0.1, ...O-key,让安装4.2.0.1:
c:\...\test5> dotnet remove package System.Data.SqlClient
c:\...\test5> dotnet add package System.Data.SqlClient --version 4.2.0.1
c:\...\test5> dotnet build有错误:
The type 'SqlCommand' is required here and is unavailable.
You must add a reference to assembly 'System.Data.SqlClient, Version=4.1.0.0, ...嗯..。替换为4.1.0.0:
c:\...\test5> dotnet remove package System.Data.SqlClient
c:\...\test5> dotnet add package System.Data.SqlClient --version 4.1.0.0
c:\...\test5> dotnet build再次出现相同的错误:
The type 'SqlCommand' is required here and is unavailable.
You must add a reference to assembly 'System.Data.SqlClient, Version=4.1.0.0, ...真的不能再往前走了。
操作系统: Windows,.NET核心: 2.1.2
发布于 2020-04-12 19:10:49
我相信其他人时不时地还在为此而苦苦挣扎,所以为了让FSharp.Data.SqlClient在苹果电脑上的.NET核心项目中运行,我必须这样做(是的,它确实工作得很好!)。
我相信其中的大部分也适用于Windows,除非你不需要Mono。
在编译时,您需要完整的.NET框架,所以如果您运行的是Linux或Mac,则必须安装Mono。该项目仍将编译为clean .NET核心。
您需要在项目文件夹中使用fsc.props (将其放置在与项目文件相同的文件夹中)。Fsc.props包含编译时使用的工具的路径。在我的fsc.props文件中,相关路径描述如下(我不记得是否必须编辑它才能让程序运行):
<PropertyGroup Condition="'$(IsOSX)' == 'true' AND Exists('/Library/Frameworks/Mono.framework/Versions/Current/Commands/fsharpc')">
<FscToolPath>/Library/Frameworks/Mono.framework/Versions/Current/Commands</FscToolPath>
<FscToolExe>fsharpc</FscToolExe>
</PropertyGroup>接下来,您需要在.fsproj文件中引用fsc.props和DisableAutoSetFscCompilerPath:
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="fsc.props" />
<PropertyGroup>
<DisableAutoSetFscCompilerPath>true</DisableAutoSetFscCompilerPath>
<DotNetFscToolPath></DotNetFscToolPath>
<DotnetFscCompilerPath></DotnetFscCompilerPath>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="mySQLCode.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Data" Version="3.3.3" />
<PackageReference Include="FSharp.Data.SqlClient" Version="2.0.6" />
</ItemGroup>
</Project>相关行是第2行到第8行。
当然,您还必须使用您最喜欢的包管理器获取Fsharp.Data和FSharp.Data.SqlClient,这会将PackageReference行添加到项目中。
快乐编码
罗兰
https://stackoverflow.com/questions/47796224
复制相似问题