This is a trick learned from the official release of ASP. NET Core 1.1 to compile the Razor view as a. dll file when Dontet publish.
You need to add the following configuration in Project.json:
1) in "Dependencies", add:
"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design": "1.1.0-preview4-final"
2) in "Tools" add:
"Tools": { "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools": "1.1.0-preview4-final"}
3) in "Scripts", add:
"Scripts": { "postpublish": "Dotnet razor-precompile--configuration%publish:configuration%--framework%publish : targetframework%--output-path%publish:outputpath%%publish:projectpath% "}
The Razor view in the ASP. NET Core project is then compiled when you run the dotnet Publish command:
Running Razor View precompilation. Precompiled views emitted to/data/aboutus/bin/release/netcoreapp1.1/ubuntu.14.04-x64/publish/ AboutUs.PrecompiledViews.dll.Successfully compiled Razor views in 12734ms.
The MVC Razor view is compiled into a AboutUs.PrecompiledViews.dll file that requires only this DLL file when running the site and does not require the. cshtml view file.
Experience precompiled MVC Razor view in ASP. NET Core 1.1