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.
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With