简体   繁体   中英

Asp.net core 2 - Files are not published

EDIT

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

I'm trying to include files in my publish process ( Currently cshtml that 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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM