码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-11-17 19:37:20      阅读:1239      评论:0      收藏:0      [点我收藏+]

标签:预编译   中学   pat   1.0   tput   frame   ase   blog   etc   

这是从 ASP.NET 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 命令时就会编译 ASP.NET 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 视图文件了。

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

标签:预编译   中学   pat   1.0   tput   frame   ase   blog   etc   

原文地址:http://www.cnblogs.com/dudu/p/6074625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!