ASP.Net 5 app.UseStaticFiles()错误输出

时间:2015-11-19 06:51:23

标签: c# asp.net visual-studio-2015 asp.net-core vs-2015-preview

严重级代码说明项目文件行 错误CS1061' IApplicationBuilder'不包含' UseStaticFiles'的定义没有扩展方法' UseStaticFiles'接受类型' IApplicationBuilder'的第一个参数。可以找到(您是否缺少using指令或程序集引用?)MyWorld.DNX Core 5.0 C:\ Projects \ MyWorld \ src \ MyWorld \ Startup.cs 21 ASP.NET5 Static File Issue

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"
  ]
}

1 个答案:

答案 0 :(得分:9)

从错误消息中,您可以看到UseStaticFiles框架可以使用DNX 4.5.1,但DNX Core 5.0

可以使用Microsoft.AspNet.StaticFiles

您应该将依赖关系dnx451添加到dnxcore50,但也应添加到project.json的{​​{1}}。您可以删除"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": { }
  }

  ...
}