salorob
October 31, 2017, 11:45am
1
Hi there!
While running ServiceStack, dotnet core, on a Raspberry Pi, i noticed that first load of my razor view pages is slow.
Once loaded, it goes like a rocket.
I don’t have any specific settings for precompilation, what-so-ever.
Is this solved by setting some options for pre-compilation of razor views, and what would be the recommended setup?
A dirty fix would be the application having to call its-self once during boot, so it’s loaded. (i know…)
What’s best ?
Rob
mythz
October 31, 2017, 3:32pm
2
Is this using Mono or .NET Core? Mono is really slow compiling Razor pages, if you’re using Mono I’d switching to .NET Core pretty much for all projects in future.
Pre-compiling the Razor views will help, there’s an example of using pre-compiled Razor Views in RazorRockstars.CompiledViews .
Otherwise I recommend checking out http://templates.servicestack.net as an alternative to Razor, Template pages don’t need to be compiled as it just uses compiled expressions which will be much faster to load.
I know, Mono is tied to my some of my posts, but i have made my switch to dotnet core in the past months voor my main project. So; its .NET Core!
I will the check pre-compile razor views article. I don’t feel like switching to Templates as my whole front-end is written in Razor views.
Many thanks.
@salorob Just in case, if you are deploying .NET Core 2.0 to a docker environment, a work around is needed for pre-compiled razor views.
opened 10:06PM - 19 Mar 17 UTC
closed 11:07PM - 31 Aug 17 UTC
bug
3 - Done
1. Use Visual Studio to create a new ASP.NET Core Web Application (.NET Framewor… k). Note: **Not** .NET Core, as I'm running my site on Mono with the full .NET Framework.
2. Add NuGet reference to `Microsoft.AspNetCore.Mvc.Razor.ViewCompilation` version 1.1.0
3. Modify the `csproj` to add:
```
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
```
4. Run
```
dotnet restore -r debian-x64
dotnet publish . -o "C:\temp\ViewPrecompilationBug_Deploy" -c Release -r debian-x64
```
Expected: Publish works as expected
Actual: Error is thrown:
```
C:\temp\ViewPrecompilationBug\ViewPrecompilationBug
λ dotnet publish . -o "C:\temp\ViewPrecompilationBug_Deploy" -c Release -r debian-x64
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
ViewPrecompilationBug -> C:\temp\ViewPrecompilationBug\ViewPrecompilationBug\bin\Release\net452\debian-x64\ViewPrecompilationBug.exe
'bin\Release\net452\debian-x64\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.exe' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\Daniel\.nuget\packages\microsoft.aspnetcore.mvc.razor.viewcompilation\1.1.0\build\net451\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets(36,5): error MSB3073: The command "bin\Release\net452\debian-x64\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.exe @"obj\Release\net452\debian-x64\microsoft.aspnetcore.mvc.razor.viewcompilation.rsp"" exited with code 9009. [C:\temp\ViewPrecompilationBug\ViewPrecompilationBug\ViewPrecompilationBug.csproj]
```
You want to use a work around which builds the precompiled views when not publishing to a stand alone deployment.
Issue is also documented here in the note.