类型或命名空间名称Web在命名空间系统中不存在

时间:2016-11-15 20:26:38

标签: c# asp.net-core

我一直在使用.NET Core 1.0.1。我只想尝试启动并运行Hello World页面。在构建期间,我遇到了以下错误:

The type or namespace name 'Web' does not exist in the namespace 'System' (are you missing an assembly reference?)

我尝试将引用添加到我的project.json:

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "System.Web": "4.0.0" //Right here
  }

但我收到错误:The dependency System.Web >= 4.0.0 could not be resolved。我似乎无法像在C#console / dll库中那样正常添加引用。

我需要安装另一个实际包含system.web程序集的软件包吗?或者有没有办法手动添加此引用?

1 个答案:

答案 0 :(得分:6)

在.NET Core中,特别是ASP.NET Core,再有 no System.Web。所有ASP.NET组件都位于Microsoft.AspNetCore.*Microsoft.Extensions.*命名空间中。

例如,HttpContext位于Microsoft.AspNetCore.HttpController位于Microsoft.AspNetCore.Mvc

我建议您阅读fundamentals of ASP.NET Core