.NET 核心 Ubuntu 14.04 上的 System.Net 出现问题

Trouble with System.Net on .NET core Ubuntu 14.04

然后我想开始使用库 System.Net 所以我更改了模板。我直接从 Microsoft API 文档中添加了 using 指令和代码片段。

我遇到错误,特别是在 System.Net 命名空间中找不到 类。请注意,编译器不会抱怨我的 using 不好(即无法识别命名空间),它只是无法在该命名空间中找到类型。

让我感到惊讶的原因是因为在 api docs 中这些 类 被指定为 .Net 核心的一部分,所以我假设它们可用 "out-of-the-box".

dotnet restore; dotnet update 产量:

sr/share/dotnet/bin/dotnet compile-csc @/home/scratch/newapp/obj/Debug/dnxcore50/dotnet-compile.rsp returned Exit Code 1
/home/scratch/newapp/Program.cs(10,13): error CS0246: The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)
ome/scratch/newapp/Program.cs(11,33): error CS0103: The name 'WebRequest' does not exist in the current context
ome/newapp/Program.cs(11,18): error CS0246: The type or namespace name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)

(原文如此:截断的 shell 输出是原样)

这是我的代码。

using System;
using System.Net;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            HttpWebRequest myReq =
                (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
            Console.WriteLine("Hello World!");
        }
    }
}

我错过了什么? .Net Core 附带的标准库中不是 System.Net 吗?我浏览了 CoreFX,但感觉它只是 .Net Core 的一个组件,我应该拥有它。如果没有,我该如何安装?

使用http://packagesearch.azurewebsites.net搜索丢失的包。然后你可以修改你的project.json,添加对找到的包的引用,比如System.Net.Primitives,System.Net.Sockets等等。

但是,对于您的情况,WebRequest 在任何 RC1 包中尚不可用。您将不得不等到 Microsoft 移植它,或者干脆切换到其他 类,例如 HttpClient。

API 参考站点目前不准确,因为我认为它是针对 RC1 和 RC2 之间的某个版本构建的。许多类型出现在 API 参考中,但它们只有在 Microsoft 发布 RC2 时才可用。