【发布时间】:2015-12-17 23:54:40
【问题描述】:
我正在尝试编写一个 C# 控制台应用程序来读取 XML 并使用 XDocument 进行处理。这看起来很简单,但我无法让智能感知识别和编译器来构建代码。我显然错过了一个参考,但看不到哪个。
程序.cs:
using System;
using System.Xml.XDocument;
using System.IO;
namespace TestVSCode
{
public class Program
{
public static void Main(string[] args)
{
XDocument _xml = XDocument.Load(File.ReadAllText(@"C:\Temp\Test.xml"));
Console.Read();
}
}
}
project.json 文件:
{
"version": "1.0.0-*",
"description": "TestVSCode Console Application",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"tooling": {
"defaultNamespace": "TestVSCode"
},
"dependencies": {
},
"commands": {
"TestVSCode": "TestVSCode"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516",
"System.Xml.XDocument": "4.0.11-beta-23516",
"System.IO": "4.0.11-beta-23516",
"System.IO.FileSystem": "4.0.1-beta-23516"
}
}
}
}
运行 dnu restore 工作正常,但 dnu build 出现此错误:
C:\Temp\TestVSCode\Program.cs(2,14): DNX,Version=v4.5.1 错误 CS0234: 类型或命名空间名称“Xml”不存在于 命名空间“系统”(您是否缺少程序集引用?) C:\Temp\TestVSCode\Program.cs(11,12): DNX,Version=v4.5.1 错误 CS0246: 类型或命名空间名称“XDocument”不能 被发现(您是否缺少 using 指令或程序集引用?) C:\Temp\TestVSCode\Program.cs(11,29): DNX,Version=v4.5.1 错误 CS0103: 当前不存在名称“XDocument” 上下文
请帮助我理解我做错了什么。
最好的问候, 维蒙德·哈加
【问题讨论】:
-
第一个问题——命名空间应该是
System.Xml.Linq,而不是System.Xml.XDocument。 -
修复
using指令后,dnxcore50构建成功。
标签: c# linq-to-xml visual-studio-code