【问题标题】:What version of Nancy package can we use for asp.net core 2.0?我们可以为 asp.net core 2.0 使用哪个版本的 Nancy 包?
【发布时间】:2017-08-18 15:55:13
【问题描述】:

不知道在哪里提出这个问题,但目前我对 NancyFX for asp.net core 2.0 很感兴趣,我尝试使用两个 2.0.0-Pre1878 版本和 2.0.0-clinteastwood 运气不佳。有没有人设法使用这些?有参考应用程序供我使用吗?

【问题讨论】:

    标签: asp.net visual-studio-code .net-core nancy


    【解决方案1】:

    试试:

    <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

    是否有参考应用程序供我使用?

    是的。

    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!");
        }
      }
    }
    

    (特别注意,您应该使用带有核心的红隼,而不是自托管,因为 Nancy.Hosting.Self 的目标是 4.6,而不是网络标准)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 2020-01-05
      相关资源
      最近更新 更多