900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 体验 ASP.NET Core 1.1 中预编译 MVC Razor 视图

体验 ASP.NET Core 1.1 中预编译 MVC Razor 视图

时间:2020-01-19 13:31:26

相关推荐

体验 ASP.NET Core 1.1 中预编译 MVC Razor 视图

这是从 Core 1.1 官方发布博文中学到的一招,可以在 dontet publish 时将 Razor 视图编译为 .dll 文件。

需要在 project.json 中添加如下配置:

1)在 "dependencies" 中添加:

"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design": "1.1.0-preview4-final"

2)在"tools"中添加:

"tools": {"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools": "1.1.0-preview4-final"}

3)在"scripts"中添加:

"scripts": {"postpublish": "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%"}

然后在运行 dotnet publish 命令时就会编译 Core 项目中的 Razor 视图:

Running Razor view precompilation.Precompiled views emitted to /data/AboutUs/bin/release/netcoreapp1.1/ubuntu.14.04-x64/publish/AboutUs.PrecompiledViews.dll.Successfully compiled 18 Razor views in 12734ms.

MVC Razor 视图被编译成了一个AboutUs.PrecompiledViews.dll 文件,运行站点时只需要这个 dll 文件,不需要 .cshtml 视图文件了。

原文地址:/dudu/p/6074625.html

.NET社区新闻,深度好文,微信中搜索dotNET跨平台或扫描二维码关注

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。