asp.net core 2.0 可以使用什么版本的 Nancy 包?

What version of Nancy package can we use for asp.net core 2.0?

不知道在哪里提出这个问题,但目前我对 NancyFX 感兴趣 asp.net core 2.0 我已经尝试同时使用 2.0 .0-Pre1878 版本和 2.0.0-clinteastwood 不太走运。有没有人设法使用这些?有没有我可以玩的参考应用程序?

尝试:

<ItemGroup> 
  <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" /> 
  <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" /> 
  <PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.0.0" /> 
  <PackageReference Include="Nancy" Version="2.0.0-clinteastwood" /> 
</ItemGroup>

(特别注意你需要Microsoft.AspNetCore.Owin

Is there a reference application for me to play with?

是的。

https://github.com/NancyFx/Nancy/tree/master/samples/Nancy.Demo.Hosting.Kestrel

最小示例:

using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Nancy;
using Nancy.Owin;

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

      host.Run();
    }
  }

  public class Startup
  {
    private readonly IConfiguration config;

    public Startup(IHostingEnvironment env)
    {
      var builder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath);
      config = builder.Build();
    }

    public void Configure(IApplicationBuilder app)
    {
      app.UseOwin(x => x.UseNancy(opt => opt.Bootstrapper = new DemoBootstrapper()));
    }
  }

  public class DemoBootstrapper : DefaultNancyBootstrapper
  {
    public DemoBootstrapper()
    {
    }
  }

  public class SampleModule : Nancy.NancyModule
  {
    public SampleModule()
    {
      Get("/", _ => "Hello World!");
    }
  }
}

(特别注意,您应该将 kestrel 与核心一起使用,而不是自托管,因为 Nancy.Hosting.Self 目标是 4.6,而不是 netstandard)