Asp.net core 2 - Files are not published

风流意气都作罢 提交于 2019-12-11 00:04:50

问题


EDIT

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

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

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

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>

回答1:


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>

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>


来源:https://stackoverflow.com/questions/49444457/asp-net-core-2-files-are-not-published

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!