-->

Precompile during publish for Azure Web Services

2019-01-23 05:29发布

问题:

We are using Azure Web Services (not Web-sites) and run ASP.Net MVC 5.1 application inside it.

When I publish web-sites through Web-deploy, I have an option to "Precompile during publishing":

When I publish to Azure Web Services, I can't find this option anywhere. Any pointers?

The idea is to pre-compile views, so first hit to a view would not be time-penalised by compiling on the fly.

I've looked on Razor Generator but it does not suit our needs. I've seen few other options, but compiling views at publishing stage makes the most sense for our case.

UPD: Just for my reference, I've tried what David Ebbo suggested and it did not work.

回答1:

Calling compiler %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -m /LM/W3SVC/1273337584/ROOT from command line on the Azure server seems to cause compilation. The Temporary ASP.Net root directory contains one directory this increases in-size and number of files contained within. The site then restarts after compilation. First page open performance then seems much better.

If I run this within a startup script it doesn't work as the site isn't avaible. I guess IIS hasn't started up. Looking at doing something like this Azure: How to execute a startup task delayed?

The site ID doesn't seem to change for different deployments. I guess could get the site id out of IIS and then use that it if it does.

So looks like that does it. Is there are more elegant way? Don't understand why compiling and deploying view files is such a chore.