F#“​​Visual Studio Code”XmlProvider未定义

时间:2017-12-25 00:57:43

标签: f# visual-studio-code

编译错误: FSharp.Data.XmlProvider未定义

Windows 10 Visual Studio Code 1.19 64位 F#4.0

f#console app targeting framework .netcoreapp2.0

尝试使用XmlProvider时出错。文档表明FSharp.Core.dll应该支持它。构建日志表示正在使用fsharp.core.dll 是C:\ Users \ KAUBUCHON.nuget \ packages \ fsharp.core \ 4.2.3 \ lib \ netstandard1.6 \ FSharp.Core.dll 而不是C:\ Program Files(x86)\ Microsoft SDKs \ F#\ 4.1 \ Framework \ v4.0 \ FSharp.Core.dll。

我的fsproj没有引用.nuget \ packages ... - 任何想法?是否错误地配置了我的环境?

下面的示例代码 - XmlProvider的类型定义失败

open System
open System.Xml.Linq
open FSharp.Data
module main =

    [<Literal>]
    let xmlsample = """
        <Customers>
        <Customer name="ACME">
        <Order Number="123">
        <OrderLine Item="widget"/>
        </Order>
        </Customer>
        </Customers>"""

    type inputXml = XmlProvider<xmlsample>
    [<EntryPoint>]
    let main argv =
        printfn "Hello World from F#!"
        0 // return an integer exit code

1 个答案:

答案 0 :(得分:0)

请遵循以下方法:https://github.com/Microsoft/visualfsharp/issues/3303

1)添加fsc.props

<?xml version="1.0" encoding="utf-8"?>
<Project>
  <!-- Type providers currently can't run inside the .NET Core 2.0 hosted compiler, see https://github.com/Microsoft/visualfsharp/pull/3658#issuecomment-334773415 -->
  <PropertyGroup>
    <IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
    <IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
    <IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
  </PropertyGroup>  
  <PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsc.exe')">
    <FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0</FscToolPath>
    <FscToolExe>fsc.exe</FscToolExe>
  </PropertyGroup>
  <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>
  <PropertyGroup Condition="'$(IsLinux)' == 'true' AND Exists('/usr/bin/fsharpc')">
    <FscToolPath>/usr/bin</FscToolPath>
    <FscToolExe>fsharpc</FscToolExe>
  </PropertyGroup>
</Project>

2)将<Import Project="fsc.props" />添加到您的fsproj作为Project元素的子节点:

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <Import Project="fsc.props" />

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
相关问题