问题描述
ServiceStack对Razor v2的新支持使用FileSystemWatcher
来检测对跟踪视图文件的更改并将其标记为无效,以便在下次请求时重新编译它们.
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.
在我的Mac OS X(山狮)上的Mono(当前运行3.0.10)上,显然存在Mono错误,其中FileSystemWatcher
不会引发文件更改的Changed
事件.此外,即使IncludeSubdirectories
设置为true,它也不会引发子目录中文件的任何事件.
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.
推荐答案
在对各种情况进行了调查和测试之后,我发现了一些针对Mono的较旧的错误报告,内容涉及FileSystemWatcher
功能的失败.
After investigating and testing various things out, I found several older bug reports against Mono about failing FileSystemWatcher
functionality.
该问题的解决方法可在Mono源代码中找到: https://github.com/mono /mono/blob/master/mcs/class/System/System.IO/FileSystemWatcher.cs
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);
如果将环境变量MONO_MANAGED_WATCHER
设置为任何值(我将其设置为启用"),则它将使用DefaultWatcher
这是一种托管实现,并且可以在Mac OS X上使用.
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");
,瞧,保存新版本后,将重新编译我的Razor视图. :)
and voila, my Razor views are recompiled after I save a new version. :)
这篇关于为什么ServiceStack Razor FileSystemWatcher在Mono + Mac OS X上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!