sudo apt-get install dotnet
安装了 dotnet dotnet new
创建了一个项目 Hello World 模板。它构建并运行。 dpkg -s
)dpkg -s
)然后我想开始使用库 System.Net 所以我改变了模板。我添加了
using
指令和直接来自 Microsoft API 文档的代码片段。我收到错误,特别是在 System.Net 命名空间中找不到这些类。请注意,编译器不会提示我的
using
不好(即无法识别命名空间),它只是无法在该命名空间中找到类型。让我感到惊讶的原因是因为在 api docs这些类被指定为 .Net 核心的一部分,所以我认为它们将是“开箱即用”的。
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!");
}
}
}
我错过了什么? System.Net 不是在 .Net Core 附带的标准库中吗?我浏览了 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 时可用。
关于.net - .NET 核心 Ubuntu 14.04 上的 System.Net 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35857629/