Razor pages compilation on Build: Now default with .Net Core 2.0

core5

.Net Core 2.0 is announced a few months back and it came up with some awesome features.

I am going to explain its one of the best features which are the compilation of views and pages on Build.

Till now(before .Net core 2.0) whenever we publish any MVC application, Razor files are published as .cshtml files and they get compiled at runtime. It means when you run the application, razor files would get compiled that time.

Which means:

  • It takes a bit more time just to compile all those cshtml files
  • Publish output size increases

.Net Core 2.0 has one inbuilt functionality which compiles page and views on the build.

It means:

  • Build the razor pages up front
  • Our Razor pages and views would get published with our app as a compiled assembly instead of being published as .cshtml source files that get compiled at runtime

So it has advantages as:

  • Reduces application startup time
  • Reduces Publish output size
  • Any problems with the razor, you can see as part of your build like compilation errors in the razor files

So the conclusion is, our .Net Core 2.0 applications are faster than the older applications.

Please note that we can disable this feature if we do not require this.

It can be done by simply updating below property in csproj file:

<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>

Apart from this, Razor pages will be updated live. Which means if you update your razor file, it would be updated in the browser at the same time.

So we can have some awesome features like Build time Razor and live refreshing of the razor pages.

Have a look here if you require more details.

 

4 thoughts on “Razor pages compilation on Build: Now default with .Net Core 2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s