2

Is there a way I can compile all my razor views (to verify) any time I need? I found this doc which shows how it compiles on publish https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-2.1&tabs=aspnetcore2x.

I am looking for an option within visual studio or even better via CLI that compiles and validates all views. I did find this official razor CLI tool in preview, but no documentation: https://www.nuget.org/packages/Microsoft.AspNetCore.Razor.Tools/1.1.0-preview4-final

2 Answers 2

2

Well, you can publish any time you need. The name ‘publish’ does not mean ‘push my site to the coliseum of public opinion’ :-)

All that it does stays local, and dotnet publish will by default create a directory under your project bin folder with, as you say, compiled views and other artefacts.

Sign up to request clarification or add additional context in comments.

Comments

1

Per this comment, with .NET core 2.1 you can compile razor views at build time without needing to publish, by adding these two lines to the <PropertyGroup> section of your project file:

<RazorCompileOnBuild>true</RazorCompileOnBuild>
<ResolvedRazorCompileToolset>RazorSdk</ResolvedRazorCompileToolset>

This will cause them to compile to a [project].Views.dll, and you'll no longer need to distribute the cshtml files.

2 Comments

yep. i have noticed this. i guess this is there by default
just noticed something about this feature today. .net core seems to create autogenerated classes to achieve this compile time checks. Knowing this might be useful for certain kinds of debugging

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.