Richard
Richard

Reputation: 462

ASP.NET PhysicalFileProvider not available in Startup.cs

I am trying to serve static files in a ASP.NET 4.6 web application, MVC 5.2.3 using the Entity Framework. I'm following this tutorial.

I'm getting a compiler error:

The type or namespace name 'PhysicalFileProvider' could not be found (are you missing a using directive or an assembly reference?)

It seems that the using Microsoft.Extensions.FileProviders is not actually being used (it is grayed out in Visual Studio.

I have tried importing various assemblies without any luck. I'm not a .NET developer and any help would be greatly appreciated.

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using Microsoft.Owin;
using Microsoft.Owin.StaticFiles;
using Microsoft.Extensions.Configuration;

using Owin;

[assembly: OwinStartup(typeof(Monica.Startup))]

namespace Monica
{
    public partial class Startup
    {

        public void Configuration(IAppBuilder app)
        {
            app.UseStaticFiles(); // For the wwwroot folder

            app.UseStaticFiles(new StaticFileOptions()
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
                RequestPath = new PathString("/StaticFiles")
            });
        }
    }
}

Upvotes: 3

Views: 4237

Answers (1)

pijemcolu
pijemcolu

Reputation: 2603

You should install the nugget package:

Microsoft.Extensions.FileProviders.Physical

Right click the project -> Manage Nugget Packages -> Browse -> Microsoft.Extensions.FileProviders.Physical -> Install.

The using statement should be available to you afterwards.

Upvotes: 6

Related Questions