11

I can't find many proper Core 1.0 tutorials yet, but when I google the method name, I get umpteen examples that say to include in Startup.cs:

app.UseDefaultFiles();
app.UseStaticFiles();

Yet I get compile errors that neither method exists on app, which is type IApplicationBuilder. Are these calls no longer required, or named totally different, or set somewhere else?

janw
  • 8,758
  • 11
  • 40
  • 62
ProfK
  • 49,207
  • 121
  • 399
  • 775

6 Answers6

11

You need to add

"Microsoft.AspNetCore.StaticFiles": "1.0.0",

in your project.json here "1.0.0" is the version you want to use

Mostafiz
  • 7,243
  • 3
  • 28
  • 42
  • 5
    New version is `"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final"`. Notice it's not `AspNet` anymore, but `AspNetCore`. – youen Jun 25 '16 at 12:42
  • @youen yes you are correct when I have answered it was `AspNet` now I updated answer using new – Mostafiz Jan 27 '17 at 14:37
  • use app.UseFileServer(); which will add both app.UseDefaultFiles(); app.UseStaticFiles(); services. – Dhanuka777 Mar 17 '17 at 05:27
8

Now with release 1.0 the correct reference will be:

"Microsoft.AspNetCore.StaticFiles": "1.0.0"
RiskX
  • 561
  • 6
  • 20
5

in your project.json make sure you have a reference

"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"

in RC2 that will likely need to change to Microsoft.AspNetCore.StaticFiles

then you should be able to use

app.UseStaticFiles();
Joe Audette
  • 35,330
  • 11
  • 106
  • 99
2

To add to Asp.Net Core Web API project using .csproj rather than project.json, you can install the package using Nuget Package Manager (search for microsoft.aspnetcore.staticfiles).

Blake Mumford
  • 17,201
  • 12
  • 49
  • 67
0

Up till today it is Microsoft.AspNetCore.StaticFiles: 1.1.0

CDspace
  • 2,639
  • 18
  • 30
  • 36
J Pace
  • 21
  • 5
0

You must change Target framework in your project properties to .Net Core 2.0:

enter image description here

janw
  • 8,758
  • 11
  • 40
  • 62
Arash Yazdani
  • 302
  • 2
  • 12