ASP.NET Core 2.0 MVC-如何从View Compilation中排除某些文件夹? [英] ASP.NET Core 2.0 MVC - how to exclude some folders from View Compilation?

查看:173
本文介绍了ASP.NET Core 2.0 MVC-如何从View Compilation中排除某些文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景-我使用此代码 https://iamrufio.com/2017/09/08/rendering-emails-with-razorviewengine-in-net-core-2-0/(感谢作者)以呈现视图字符串(用于电子邮件).但是,当您发布项目时,所有视图都会被编译,因此我松开了Views/Emails/[templates].发布时如何排除某些文件夹不被编译(而不部署)?

Here's the scenario - I use this code https://iamrufio.com/2017/09/08/rendering-emails-with-razorviewengine-in-net-core-2-0/ (thanks to author) to render views to string (for emails). But when you publish the project all views get compiled, so I loose my Views/Emails/[templates]. How can I exclude some folders from being compiled (and not deployed) when publishing?

我找到了这个 https://github.com/aspnet/MvcPrecompilation ,并使用了MvcRazorExcludeViewFilesFromPublish set to false而且有效.但是现在我已经部署了所有视图(我想知道它们是否仍是预编译的吗?).没什么大不了,但我只会部署其中一些.

I found this https://github.com/aspnet/MvcPrecompilation and used MvcRazorExcludeViewFilesFromPublish set to false and it worked. But now I have all my Views deployed (are they still precompiled I wonder?). Not a big deal but I'd have only some of them deployed.

推荐答案

您可以尝试一下,它对我有用.

You can try this, its working for me.

  • 将MvcRazorCompileOnPublish保留为true(默认值).
  • 使用视图不应排除文件夹 templates 文件夹 从项目预编译.您可以使用排除来自 Project 上下文菜单选项,或将此代码包含在 .csproj 文件中:
  • Leave MvcRazorCompileOnPublish to true (default).
  • Exclude your folder templates folder with views which should not be precompiled from project. You can do this with Exclude From Project context menu options, or with this code in .csproj file:
<ItemGroup>
    <Compile Remove="Views\Emails\templates\**" />
    <Content Remove="Views\Emails\templates\**" />
    <EmbeddedResource Remove="Views\Emails\templates\**" />
    <None Remove="Views\Emails\templates\**" />
</ItemGroup>

  • 如果您现在发布项目,则会创建 .PrecompiledViews.dll ,但是 模板文件夹中没有视图.
  • 您可以手动(或使用自定义任务)复制 templates 文件夹以发布根目录.
  • 现在可以在此外部文件夹中找到视图,但是您可能最终会遇到错误:
    • If you now publish project, .PrecompiledViews.dll is created, but without views in templates folder.
    • You can manualy (or with custom task) copy templates folder to publish root directory.
    • Now views is find in this external folder, but you probably endup with error:
    • 找不到包的编译库位置 "Microsoft.Win32.Registry"

      Cannot find compilation library location for package 'Microsoft.Win32.Registry'

      要解决此问题,您必须发布文件夹添加引用 带有某些运行时程序集的子文件夹.如果您在 MvcRazorCompileOnPublish 设置为 false 的情况下发布项目,则通常会创建该 refs 文件夹.因此,您必须一次不进行预编译就将其发布到另一个文件夹,然后从该文件夹复制此refs子文件夹.

      To correct this, you must to publish folder add refs subfolder with some runtime assemblies. This refs folder is normaly created if you do publish project with MvcRazorCompileOnPublish set to false. So you must one time do publish without precompilation to another folder and copy this refs subfolder from there.

      这篇关于ASP.NET Core 2.0 MVC-如何从View Compilation中排除某些文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆