ASP.NET Core 2-文件未发布 [英] Asp.net core 2 - Files are not published

查看:95
本文介绍了ASP.NET Core 2-文件未发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑

有关信息,我正在使用VS Code在macOS上进行开发

For info, I'm developping on macOS using VS Code

我正在尝试在发布过程中包括文件(当前 cshtml 代表我的电子邮件模板)。

I'm trying to include files in my publish process ( Currently cshtmlthat represents my email templates ).

我在github上遵循此线程,但似乎他们的解决方案不适用于我。

I follow this thread on github but seems that their solutions don't work for me.

我的csproj在其中添加唯一的 cshtml 文件:

Here my csproj to add an unique cshtml file :

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <ItemGroup>
      <EmailFile Include="$(ProjectDir)/EmailTemplates/OrderCompleteEmail.cshtml" />
    </ItemGroup>
    <Copy SourceFiles="@(EmailFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" />
  </Target>


推荐答案

您的解决方案几乎是正确的,您必须使用 AfterTargets =发布

Your solution was almost correct, you have to use AfterTargets="Publish":

<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
  <ItemGroup>
    <EmailFile Include="EmailTemplates/OrderCompleteEmail.cshtml" />
  </ItemGroup>
  <Copy SourceFiles="@(EmailFile)" DestinationFolder="$(PublishDir)" />
</Target>

您还可以将单个Target中的所有电子邮件模板复制到同一文件夹,例如:

You can also copy all your email templates in a single Target to the same folder like:

  <Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
    <ItemGroup>
      <EmailTemplates Include="EmailTemplates\*.cshtml" />
    </ItemGroup>
    <Copy SourceFiles="@(EmailTemplates)" DestinationFolder="$(PublishDir)%(EmailTemplates.RelativeDir)" />
  </Target>

这篇关于ASP.NET Core 2-文件未发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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