找不到类型或命名空间名称 'Ping',尽管存在依赖关系和使用

The type or namespace name 'Ping' could not be found, although there is a dependencie and a using

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

的 class ping
namespace System.Net.NetworkInformation.Ping

我正在使用 ASP.NET 5.0,所以我有 project.json 文件和我的依赖项

  {
    "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();   
        }

    }
}

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

Code:Error CS0246 Description:The type or namespace name 'Ping' could not be found (are you missing a using directive or an assembly reference?) Project:TestApp.ASP.NET Core 5.0 file:Program.cs line:9

问题是 Ping 不在 CoreCLR (aspnetcore50) 的 System.Net.NetworkInfomation 包中(该包是否存在?)。

根据package search website,您需要添加对System.Net.Utilities包的引用。