严重性代码描述项目文件行
错误CS1061'IApplicationBuilder'不包含'UseStaticFiles'的定义,并且找不到扩展方法'UseStaticFiles'接受类型为'IApplicationBuilder'的第一个参数(您是否缺少using指令或程序集引用?)MyWorld.DNX Core 5.0 C:\Projects\MyWorld\src\MyWorld\Startup.cs 21
c# - ASP.Net 5 app.UseStaticFiles()错误输出-LMLPHP

Project.json

{
  "webroot": "wwwroot",
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel"
  },

  "frameworks": {
    "dnx451": {
      "dependencies": {
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta8"
      }
    },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

最佳答案

从错误消息中,您可以看到UseStaticFiles可用于DNX 4.5.1框架,但不适用于DNX Core 5.0
您不仅应该将依赖项添加到Microsoft.AspNet.StaticFiles中,还应该添加到dnx451中的dnxcore50中,还应该添加到project.json中。您可以删除"frameworks"键中的依赖关系并将其放在"dependencies"键中,以使其可用于两个框架

{
  ...

  "dependencies": {
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
  },

  ...

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  }

  ...
}

关于c# - ASP.Net 5 app.UseStaticFiles()错误输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33797071/

10-12 22:36