不确定在哪里提出这个问题,但目前我对asp.net core 2.0的 NancyFX 感兴趣我试图同时使用 2.0.0-Pre1878 版本和 2.0.0-clinteastwood 没有太多运气。有没有人设法使用这些?我有参考申请吗?
答案 0 :(得分:4)
尝试:
<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,而不是netstandard)