找不到方法app.UseStaticFiles() [英] Can't find method app.UseStaticFiles()

查看:342
本文介绍了找不到方法app.UseStaticFiles()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注本指南在第4步中,系统要求我在 project.json 文件中添加三行(我这样做了,然后运行 dotnet restore 得到很多更新的软件包).

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).

当我在 Configure 方法中输入三行时,所有行上都出现红线.无法识别该方法,未提供智能感知等.

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.

我还注意到,在本指南的示例中,方法签名仅采用 IApplicationBuilder 的一个参数,而生成的参数是使用( yo aspnet 命令生成的) )看起来像这样.

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);

我不确定该如何解决.我的猜测是,此过程中有一个新版本的东西(Yo,Generators,Core等),但我不确定.

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?

推荐答案

从链接的教程中的屏幕截图来看,它与ASP.NET Core RC1有关(当时称为ASP.NET 5 r1-final).您可以在包和名称空间名称上轻松识别这一点. Microsoft.AspNet.*一直使用到rc1.

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.

从RC2开始,这些软件包已重命名为Microsoft.AspNetCore.*,以使其更清楚其新框架,并且与旧版ASP.NET的兼容性不高.

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.

UseIISPlatformHandler()不再存在,它现在在Main(...)方法中的UseIISIntegration()中:

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();
    }
}

包,包是Microsoft.AspNetCore.Server.IISIntegration": "1.0.0""Microsoft.AspNetCore.Server.Kestrel": "1.0.1".对于静态文件,它是:"Microsoft.AspNetCore.StaticFiles": "1.0.0".

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".

对于Configure重载:Configure(IApplicationBuilder);是默认值,但是您可以添加在依赖项注入系统中注册的任何其他类型(在ConfigureServices方法中),因为它是一个约定俗成的系统(startup.cs ).

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).

这篇关于找不到方法app.UseStaticFiles()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆