Copy Razor-Views for Self-hosting NancyFx?

2019-04-28 13:05发布

I started out with a simple MVC-site using NancyFx with Razor-views (.cshtml) and Nancy.Hosting.Aspnet, using IIS Express. Now I adapted the project to a self-hosting service using Nancy.Hosting.Self (and TopShelf).

However, to provide the Views, it seems I need to change their properties from None & Do not copy to Content & Copy if newer, so they are copied to .\bin\Debug\.

One consequence is that changes to the Views will not be shown/updated until a restart. Even when working in debug-mode, where caching is disabled by default. I know this is just a minor annoyance, but still an annoyance, and it is nice to be able to try (cs)HTML-changes right away. So I was wondering is there a way to fix this, e.g. to prevent having to set the files to Copy if newer?

2条回答
Deceive 欺骗
2楼-- · 2019-04-28 13:23

You will need to set these values:

#if DEBUG
  StaticConfiguration.Caching.EnableRuntimeViewDiscovery = true
  EnableRuntimeViewUpdates = true
#endif
查看更多
Root(大扎)
3楼-- · 2019-04-28 13:31

You can provide a custom root path that looks directly at the views folder in your project.

查看更多
登录 后发表回答