在面向.NET Framework 4.6.2的F#可执行文件中,加载,修改XML文件,然后通过System.Xml.Linq将其保存回磁盘:
let doc = XDocument.Load apiDoc
...file is modified....
doc.Save apiDoc
将项目从Visual Studio 2015移动到Forge / FAKE / IonIDE并执行:
遇到以下错误:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or
assembly 'System.Core, Version=3.5.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot find the
file specified.
at System.Xml.Linq.XText.WriteTo(XmlWriter writer)
at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
at System.Xml.Linq.XElement.WriteTo(XmlWriter writer)
at System.Xml.Linq.XDocument.WriteTo(XmlWriter writer)
at System.Xml.Linq.XDocument.Save(XmlWriter writer)
at System.Xml.Linq.XDocument.Save(String fileName, SaveOptions options)
at System.Xml.Linq.XDocument.Save(String fileName)
at Migrate.main(String[] argv) in c:\Projects\Migration\src\app\Migration\Migrate.fs:line 133
我在加载文档之前尝试添加以下内容,但发生了同样的错误:
Assembly.Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") |> ignore
注意:
这让我感到困惑,因为4.6.2没有3.5依赖关系,并且错误中给出的预期引用没有强名称。
答案 0 :(得分:0)
这是我学习VSCode / Ionide的一个例子。首次设置项目时,System.Xml.Linq无法解析。我错误地将它添加到没有版本约束的paket.references文件中。这促使Paket下拉Mono package。作为3.5版本的软件包,它对System.Core版本3.5具有隐式依赖性。
从项目中删除软件包,然后在Ionide中使用预期的F#:Add Reference命令后,项目中添加了正确的4.6.2框架参考。
答案 1 :(得分:0)
对于使用FSharp脚本的用户,您可以引用该程序集,然后打开System.Xml.Linq
:
#r "System.Xml.Linq.dll"
open System.Xml.Linq