ServiceStack: Self-Host LiveReload not working

2019-03-02 04:19发布

问题:

I have a self hosted ServiceStack application which I intend to use to develop an angular application with.

The problem is, previously, every time I've made a change to a static file, I've had to restart all the services for it to pick up the changes.

I'm wondering if I'm missing something? I've enabled the LiveReload option from RazorFormat but it doesnt seem to have done anything? I still have to restart the whole application for it to pick up changes?

I've created a small repro here: https://github.com/CallumVass/ServiceStackSelfHost

If I make changes to the Default.cshtml file the changes arent picked up until I restart the service?

回答1:

The issue is that he was changing the source file and not the output file. Since SS copies the files to /bin/debug he needed to change that version.

Using HostConfig settings, we were able to to use the WebHostPhysicalPath property in the following way during development, while setting up the SS Config:

SetConfig(new HostConfig {
#if DEBUG
    DebugMode = true,
    WebHostPhysicalPath = Path.GetFullPath(Path.Combine("~".MapServerPath(), "..", "..")),
#endif
});

This took us out of /bin/debug and back to the source.



回答2:

You need to set the AppHost config to debug mode:

SetConfig(new HostConfig {
    DebugMode = true,
});

For performance reasons changes are only monitored for in Debug mode. See here for more information.

Automatic reload of modified views, layout templates and partials (in Debug mode)

The best way to avoid the Start-Up penalty is to avoid having to restart the AppDomain in the first place. So in Debug Mode we'll also do this where a background file system watcher monitors all pages, partials and Layout templates for modifications and recompiles and auto-reloads them on the fly, all-ready to deliever instant response time once the page is requested.