No Static Files Extensions are referable

2019-07-26 10:35发布

问题:

I have Microsoft.AspNet.StaticFiles referenced in my project.json, but the UseDefaultFiles() and UseStaticFiles() extensions are still not recognised.

The dependencies section of project.json is:

"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.0.0-rc2-3002702",
    "type": "platform"
  },
  "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
  "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
}

I can see the reference in the references section of the solution explorer. I can see in the Git repo that it lives in the Microsoft.AspNetCore.Builder namespace, as does UseDefaultFiles() but I just get a compile error:

IApplicationBuilder' does not contain a definition for 'UseDefaultFiles' and no extension method 'UseDefaultFiles' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

I can, however, access the middleware directly without the extension methods:

app.UseMiddleware<StaticFileMiddleware>();
app.UseMiddleware<DefaultFilesMiddleware>();

is fine.

What's going on?

回答1:

Like Daniel Grim says:

Change the dependency to:

  "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final"

Package: https://www.nuget.org/packages/Microsoft.AspNetCore.StaticFiles/1.0.0-rc2-final