Why doesn't the ServiceStack Razor FileSystemWatcher work on Mono + Mac OS X?

寵の児 提交于 2019-12-22 10:56:19

问题


ServiceStack's new support for Razor v2 uses a FileSystemWatcher to detect changes to tracked view files and mark them as invalid so they'll be recompiled at the next request.

This is great for debugging as it lets you edit your views and not rebuild/restart your project.

On Mono (currently running 3.0.10) on my Mac OS X (Mountain Lion) there is apparently a Mono bug where the FileSystemWatcher doesn't raise Changed events for file changes. Furthermore, it also doesn't raise any events for files in a subdirectory, even if IncludeSubdirectories is set to true.


回答1:


After investigating and testing various things out, I found several older bug reports against Mono about failing FileSystemWatcher functionality.

The workaround to the problem is found in the Mono source: https://github.com/mono/mono/blob/master/mcs/class/System/System.IO/FileSystemWatcher.cs

string managed = Environment.GetEnvironmentVariable ("MONO_MANAGED_WATCHER");
...
if (String.Compare (managed, "disabled", true) == 0)
    NullFileWatcher.GetInstance (out watcher);
else
    DefaultWatcher.GetInstance (out watcher);

If you set the environment variable MONO_MANAGED_WATCHER to anything (I set it to "enabled") then it will use the DefaultWatcher which is a managed implementation, and it works on Mac OS X.

So during my application startup, I added:

Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");

and voila, my Razor views are recompiled after I save a new version. :)




回答2:


it works but mono begins to consume a lot of CPU time: ~70% of one core.



来源:https://stackoverflow.com/questions/16859372/why-doesnt-the-servicestack-razor-filesystemwatcher-work-on-mono-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!