Is it possible to use Razor as a standalone librar

2019-05-05 14:30发布

问题:

I would like to write a proof of concept MonoMac app which renders html "Views" using c# and Razor.

Is this possible?

If not, does anyone recommend any other Templating engines that compare to the simplicity of Razor. I don't mind writing it in Objective-C if I have to, but Mono would be simpler.

回答1:

I think you may be interested in this project. You just have to download zip which consists of two DLLs, reference them in your project and examples like these just works. Have in mind that you have to make 4.0 project. I have been testing this on Mono 2.10.5, however OS was Linux, not OS X, because I don't have one. It shouldn't be a problem nevertheless.

Another approach is to do something like mentioned here. Post is quite old and libraries' names has changed but you should be able to use one which are downloadable here. The first approach is cleaner, however I am not sure if it is what you need.

You can also find this project interesting.