C# – ASP.Net 5 app.UseStaticFiles() error out

asp.netasp.net-corecvisual-studio-2015

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

Best Answer

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

  ...
}
Related Topic