Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net 5 app.UseStaticFiles() error out

Severity Code Description Project File Line Error CS1061 'IApplicationBuilder' does not contain a definition for 'UseStaticFiles' and no extension method 'UseStaticFiles' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?) 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"
  ]
}
like image 903
user5555457 Avatar asked Nov 19 '15 06:11

user5555457


1 Answers

From your error message you can see that UseStaticFiles is available to DNX 4.5.1 framework but not to DNX Core 5.0

You should add the dependency to Microsoft.AspNet.StaticFiles not only to dnx451 but also to dnxcore50 in your project.json. You can remove the depency in the "frameworks" key and put it inside the "dependencies" key to make it available for both frameworks

{
  ...

  "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": { }
  }

  ...
}
like image 183
Carlos Muñoz Avatar answered Nov 05 '22 21:11

Carlos Muñoz