简体   繁体   English

ASP.NET Core MVC 2.1 查看编译发布到 Azure

[英]ASP.NET Core MVC 2.1 View Compilation on Publish to Azure

I created a class that inherits from RazorProjectFileSystem that performs minification on cshtml files prior to them being compiled.我创建了一个继承自 RazorProjectFileSystem 的 class,它在编译 cshtml 文件之前对其执行缩小。 This is configured in Startup.ConfigureServices .这是在Startup.ConfigureServices中配置的。

Works just fine when running locally, stripping out a mass of whitespace and comments.在本地运行时工作得很好,去掉了大量的空白和注释。 However when the site is published to Azure a ProjectName.Views.dll is created, which completely bypasses my logic.但是,当站点发布到 Azure 时,会创建一个ProjectName.Views.dll ,这完全绕过了我的逻辑。

I still want to use precompiled views (and yes, we are using gzip compression as well), but will need to plug my logic somewhere else in the chain to get this to happen.我仍然想使用预编译的视图(是的,我们也在使用 gzip 压缩),但是需要将我的逻辑插入到链中的其他位置才能实现。 However I can't find any information on where the.cshtml files are read from the file system as part of the creation of the View.dll.但是,作为创建 View.dll 的一部分,我找不到任何关于从文件系统中读取 .cshtml 文件的位置的任何信息。

I suspect we may need to run the minification prior to the actual build process itself.我怀疑我们可能需要在实际构建过程本身之前运行缩小。 Any ideas or recommendations very much appreciated.非常感谢任何想法或建议。

There are many libraries available to do build time minification of CSHTML files, you can use **gulp-cshtml-minify** .有许多库可用于缩小 CSHTML 文件的构建时间,您可以使用**gulp-cshtml-minify** Only problem with this one is that you have to install node and gulp for using this.唯一的问题是您必须安装节点和 gulp 才能使用它。

Here is a detailed elaboration on this.这是对此的详细阐述。 which you can find it in below blog:您可以在下面的博客中找到它:

https://debugandrelease.blogspot.com/2018/11/automatically-minifying-cshtml-files-in.html https://debugandrelease.blogspot.com/2018/11/automatically-minifying-cshtml-files-in.html

Only thing which you have to do is append.min word while pulling the vies from the folder like below:您唯一需要做的就是 append.min 字,同时从如下文件夹中拉出 vies:

public override ViewResult View(string viewName, object model)
        {
            if (!IsDevelopment())
            {
                string action = ControllerContext.RouteData.Values["action"].ToString();

                if (string.IsNullOrEmpty(viewName))
                {
                    viewName = $"{action}.min";
                }                    
                else if (viewName == action)
                {
                    viewName += ".min";
                }
            }

            return base.View(viewName, model);
        }

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 查看asp.net mvc和asp.net core mvc的目录编译时间差 - View directory compilation time difference between asp.net mvc and asp.net core mvc ASP.NET Core 2.1。 MVC视图中的Razor UI类库 - ASP.NET Core 2.1. Razor UI Class Library in MVC View ASP.NET Core 2.1 MVC中的部分属性绑定/发布 - Partial Properties Binding/Posting in ASP.NET Core 2.1 MVC 将ASP.NET MVC 5网站发布到Windows Azure - Publish ASP.NET MVC 5 website to Windows Azure 是否可以使用Asp.Net MVC 4将网站发布为子网站以进行天蓝色 - Is it possible to publish a website as a subsite to azure using Asp.Net MVC 4 ASP.NET MVC身份与ASP.Net核心2.1身份(它们之间的交叉身份验证) - ASP.NET MVC Identity vs ASP.Net core 2.1 Identity (Cross authentication between them) ASP.NET MVC强类型视图编译错误 - ASP.NET MVC strongly typed view compilation error Asp.net Core 2.1-布局控制器 - Asp.net core 2.1 - Layout controller Asp.net MVC Core 1.1中的MVC视图未刷新 - Mvc view is not getting refreshed in Asp.net mvc core 1.1 在 ASP.NET Core 2.1 MVC 中使用 Entity Framework Core 搭建新控制器的问题 - Problem scaffolding new controller using Entity Framework Core in ASP.NET Core 2.1 MVC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM