虽然存在依赖关系和使用,但找不到类型或命名空间名称“Ping”

我正在创建一个程序来ping网络中的计算机。 为此,我试图使用类ping,来自

namespace System.Net.NetworkInformation.Ping 

我正在使用ASP.NET 5.0所以我hava project.json文件与我的dependecies

  { "version": "1.0.0-*", "dependencies": { "NetworkSniffer": "1.0.0-*", "Microsoft.AspNet.Mvc": "6.0.0.0-beta2" }, "commands": { "run": "run" }, "frameworks": { "aspnet50": { "dependencies": { "System.Console": "4.0.0-beta-22231", "System.Net.NetworkInformation": "4.0.10-beta-22231" } }, "aspnetcore50": { "dependencies": { "System.Console": "4.0.0-beta-22231", "System.Net.NetworkInformation": "4.0.10-beta-22231" } } } } 

一个简单版本的控制台代码仍然给出错误:

 using System.Net.NetworkInformation; namespace TestApp { public class Program { public static void Main(string[] args) { Ping p = new Ping(); } } } 

尝试编译此代码时的完整错误是:

代码:错误CS0246描述:找不到类型或命名空间名称’Ping’(您是否缺少using指令或程序集引用?)项目:TestApp.ASP.NET Core 5.0文件:Program.cs行:9

问题是Ping不在System.Net.NetworkInfomation包中(该包甚至存在?)用于CoreCLR( aspnetcore50 )。

根据包搜索网站 ,您需要添加对System.Net.Utilities包的引用。