可以';不要在ASP.NET Core中使用中间件

本文关键字:Core NET 中间件 ASP 可以 | 更新日期: 2023-09-27 18:01:03

按照Scott Allen的Pluralsight课程,我正在尝试组装一个小的ASP.NET Core应用程序。我在macOS上。

我的project.json依赖项如下所示:

        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        },
        "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
        "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"

我恢复了所有必要的程序包。

我的Startup.cs看起来像这样:

...
 public void Configure(IApplicationBuilder app)
 {
      app.UseFileServer(); // 'IApplicationBuilder' does not contain a definition for 'UseFileServer' and no extension method 'UseFileServer' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?) [netcoreapp1.0]
      app.Run(context =>
      {
          return context.Response.WriteAsync("Hello from ASP.NET Core!");
       });
  }
...

我似乎已经准备好了所有的依赖项,但编译器抱怨没有看到任何中间件的扩展方法(例如UseFileServer(

有什么想法吗?

可以';不要在ASP.NET Core中使用中间件

您需要将"Microsoft.AspNetCore.StaticFiles" : "1.0.0"依赖项添加到您的project.json文件中,或者在错误上单击Ctrl+.时遵循IDE的建议(但不知道它是否在Visual Studio代码中有效(。

此外,您可能必须包含Microsoft.AspNetCore.Builder命名空间,因为UseFileServer位于静态文件库