Can't find method app.UseStaticFiles()
Asked Answered
P

3

0

I'm following this guide and in step 4, I'm asked to add three lines to the project.json file (which I did and then ran dotnet restore getting a lot of updated packages).

When I enter the three lines in the Configure method, I get red lines on all of them. The methods aren't recognized, no intellisense provided etc.

I also noticed that in the example in the guide, the method signature only takes one parameter of IApplicationBuilder, whereas the one I got generated (using the yo aspnet command) looks like this.

Configure(IApplicationBuilder, IHostingEnvironment, ILoggerFactory);

I'm not sure how to resolve it. My guess is that there's a new version of something in the process (Yo, Generators, Core etc.) but I'm not entirely sure.

I've also found this blog where the method signature resembles the one I'm getting. However, the author of it suggest the same syntax that doesn't work for me. I'm guessing it's a matter of referencing the wrong libraries. How do I approach the issue?

Perceptual answered 12/11, 2016 at 21:58 Comment(5)
First the tutorial uses an outdated version, at least the screenshots are rc1 which you shouldn't depend on anymore. Anything older than rc2 you can safely trash away, because changes from rc1 to rc2 were to big (changed from dnx to dotnet cli, package and namespaces changed too and quite a few bits of the API too)Firstly
@Firstly That is so uncool... I've wasted most of the Saturday boinking my had in the table to grasp all of this because it didn't make any sense... Should have asked earlier, hehe. Thanks! Post it as a reply too. It needs accepting.Perceptual
@Firstly Is all that talk about the Yo package also obsolete or is it still being used? I can't tell...Perceptual
dunno about yo, never used it. I create my projects always within Visual Studio 2015. Depends which kind of template it creates, look at the dependencies. If the dependencies are all Microsoft.AspNet.* then you can trash it as its outdated. If they are Microsoft.AspNetCore.* then they are at least rc2 or rtm (which the version number can clear up)Firstly
@Firstly It's AspNetCore, yey! Also, once again, this should go as an answer, not a comment.Perceptual
F
1

Judging from the screenshots in the linked tutorial, its about ASP.NET Core RC1 (back then called ASP.NET 5 r1-final). You can easily recognize this on the package and namespace names. Microsoft.AspNet.* is used until rc1.

Starting with RC2 the packages were renamed to Microsoft.AspNetCore.* to make it clearer its a new framework and not that much compatible with legacy ASP.NET.

The UseIISPlatformHandler() isn't there anymore, it's now UseIISIntegration() within the Main(...) method:

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

And the packages the package is Microsoft.AspNetCore.Server.IISIntegration": "1.0.0" and "Microsoft.AspNetCore.Server.Kestrel": "1.0.1". For static files it's: "Microsoft.AspNetCore.StaticFiles": "1.0.0".

For the Configure overload: Configure(IApplicationBuilder); is default one, but you can add any other type which is registered with the dependency injection system (in ConfigureServices method), as it's a convention system (the startup.cs).

Firstly answered 12/11, 2016 at 23:41 Comment(0)
H
6

For Asp.Net core MVC you need to install Nuget package

install-package "Microsoft.AspNetCore.StaticFiles"

Hindbrain answered 17/3, 2017 at 5:5 Comment(0)
G
3

That guide is outdated. The updated .Net core does not use project.json anymore which is unfortunate. Instead it is now part of csproj file. And to add the Static file library you have to add it to the project using nuget packet manager. And when you rebuild you will see an entry in csproj file for that library. I think the project.json was a great idea which was inline with core opt-in methodology, since it would allow intellisense to kick in to help you select from available libraries. And since csproj file cant be directly edited in solution you lose that feature.

Grommet answered 31/3, 2017 at 15:48 Comment(0)
F
1

Judging from the screenshots in the linked tutorial, its about ASP.NET Core RC1 (back then called ASP.NET 5 r1-final). You can easily recognize this on the package and namespace names. Microsoft.AspNet.* is used until rc1.

Starting with RC2 the packages were renamed to Microsoft.AspNetCore.* to make it clearer its a new framework and not that much compatible with legacy ASP.NET.

The UseIISPlatformHandler() isn't there anymore, it's now UseIISIntegration() within the Main(...) method:

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

And the packages the package is Microsoft.AspNetCore.Server.IISIntegration": "1.0.0" and "Microsoft.AspNetCore.Server.Kestrel": "1.0.1". For static files it's: "Microsoft.AspNetCore.StaticFiles": "1.0.0".

For the Configure overload: Configure(IApplicationBuilder); is default one, but you can add any other type which is registered with the dependency injection system (in ConfigureServices method), as it's a convention system (the startup.cs).

Firstly answered 12/11, 2016 at 23:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.