Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Precompile ASP.NET MVC views on Azure Web App

Is there a way to precompile the ASP.NET MVC views on an Azure Web App (specifically when published via Release Management on VSTS)?

Once each view has been hit once, the page subsequently renders very quickly. But that first delay can be a doozy for users and there's no way to script touching each page.

I'm not sure if I need to change something in the build/release processes on VSTS (I am using the Visual Studio Build build step and the Azure Web App release task) or if I need to run something on the Azure Web App instance after it is released (or something else altogether).

It seems like finding some way to call aspnet_compiler after publish might be what I need (and I have seen that in reference to Web Roles on Cloud Services) but I can't get that to work.

Calling

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -v "/" -p "d:\home\site\wwwroot" 

via the Console in the Azure Portal executes just fine (and finds errors if there are any) but doesn't have any impact on startup time - hitting a view the first time still takes a long time.

So maybe that isn't the right direction.

I've looked at RazorGenerator (including the .MSBuild nuget package) and I couldn't quite get it to work, but really I was hesitant to make so many changes to the projects just to get precompilation on release.

Also note that I am currently using TFVC, not Git, in VSTS, so the Kudu/Git integration (that does seem to trigger the precompilation according to some articles) isn't available to me as far as I can tell.

Other ideas?

like image 771
Tim Avatar asked May 12 '16 17:05

Tim


People also ask

What ASP NET deployment method is used to precompile website content before installation?

Performing Precompilation You can precompile a Web site using the Aspnet_compiler.exe tool on the command line. For more information, see How to: Precompile ASP.NET Web Sites for Deployment and ASP.NET Compilation Tool (Aspnet_compiler.exe). Visual Studio also includes commands to precompile a Web site from the IDE.

How do I publish my MVC application to Azure?

Publishing the MVC applicationOpen the MVC project's solution in Visual Studio. Right-click the project in the Solution Explorer and select Publish.... Select Microsoft Azure App Service and choose Select Existing. Click Publish.

What is precompiled in c#?

When precompiling for deployment, the compilation tool creates a target location folder, compiles the specified web application's source code, and copies these compiled assemblies and the content files into the target location folder.


2 Answers

You can add "/p:PrecompileBeforePublish=true" argument in "Visual Studio Build" step: enter image description here

Then the task will call aspnet_compiler during the build process and generate a precompiled output for deployment.

like image 140
Eddie Chen - MSFT Avatar answered Oct 27 '22 22:10

Eddie Chen - MSFT


In visual studio 2013+, choose Build->Profiles. Select the profile, then choose "Settings". Underneath "Configuration", expand "File Publish Options", and then check the "Precompile during publishing" option.

like image 26
1c1cle Avatar answered Oct 27 '22 20:10

1c1cle