F#“ Visual Studio Code”XmlProvider未定义

问题描述 投票:2回答:1

编译错误: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 SDK \ F#\ 4.1 \ Framework \ v4.0 \ FSharp.Core.dll。

我的csproj没有引用.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
f# visual-studio-code
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.