Using the Razor Engine in a console application

I am using the Razor Engine from CodePlex in a console application. When I run in debug mode in the VS 2010 IDE, everything works. From the shell, even a simple 2-liner in the example on the CodePlex page above crashes. Therefore, I do not think this is code. The exception message is as general as it can be:

RazorEngine.Templating.TemplateCompilationException: Unable to compile template. 

All DLL files that are referenced (in the "Links" section) are located in the working directory along with .exe, which itself is a console application. I will not list the entire list here, but here are some of them that I consider relevant: System.Web , System.Web.Mvc , System.Web.Razor , RazorEngine , etc. I do not think DLLs such as System , System.Xml , etc. You even need to be there, but to eliminate any surprise, I copied them anyway. The fact is that in the "Links" section is copied to the working directory where exe is located. Surprisingly, this still does not work. How can I track the missing or just make this work?

Edit I just created a console console application to demonstrate my point of view. Here is the whole program. As I mentioned, it works great inside the IDE, not in the shell.

 using System; using RazorEngine; namespace RazorEngineTest { public class Program { public static void Main(string[] args) { string template = "Hello @Model.Name! Welcome to Razor!"; string result = Razor.Parse(template, new { Name = "World" }); Console.WriteLine(result); Console.ReadLine(); } } } 
+6
source share

Source: https://habr.com/ru/post/903000/


All Articles