Is there a way to enable compilation of cshtml templates in a class library project in assembly?

I am currently using RazorEngine in a non web app.

I have a class library that contains the template files, the models used in the templates, and a RazorEngine wrapper to set it up correctly and ensure easy template handling.

I followed the instructions on how to enable intellisense and it works fine.

Currently, when I build the project, the build will succeed even if there are errors in the templates. If I open all of the template files, the errors found will appear on the Error List tab. But even if I create a project with all these files open and errors in the error list, then the build still succeeds.

If it was a web project I could use "MvcBuildViews" according to this question . But since I am in a class library project, I would assume that the build infrastructure that supports this setting was not included in the project and therefore does not affect anything.

I have a google search in general and SO in particular, but I couldn't find anything about what it would take to add these build functionality to my project.

Getting build errors and preventing build success when there are errors is my main goal.

Is there an easy way to check for razor assembly errors?

Is there some easy way to add the required functionality to the build process for an existing project?

Am I the only option to start with a web project and then delete whatever I don't need and pretend it's a class library project?

+3


source to share


1 answer


Is there an easy way to check for razor assembly errors?

No, which I know about. https://github.com/vladimir-shmidt said on Gitter that it compiles templates at build time and includes the results as resources. But I think the code is not available.

Is there some easy way to add the required functionality to the build process for an existing project?

Depends on your dependencies, but "should" be simple enough:



  • Add a new console application to your solution
  • Linking to a Project Using Razor Templates
  • Use Engine.Razor.Compile

    to compile templates (in a console application)
  • Add a build step to run a console application

Hope this helps / works,

matthid, contributor to RazorEngine

+3


source







All Articles