3

Is it possible to include some files on publishing and put them in specific folder.

I would like to put all report files (*.rdlc) in folder Reports in the publish location.

I tried with:

<ItemGroup>
    <Content Include="..\Reports\**\*.rdlc"
             PackagePath="\Reports"
             CopyToPublishDirectory="Always"/>
</ItemGroup>

But it always puts files in to the root of the published destination.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Igor
  • 381
  • 3
  • 17
  • Possible duplicate of [ASP.NET Core: Exclude or include files on publish](https://stackoverflow.com/questions/42712055/asp-net-core-exclude-or-include-files-on-publish) – Set Aug 16 '17 at 10:32
  • I saw that post, but it does not work for me. It seems that Content does not recognize PackagePath attribute. It put files into root. – Igor Aug 16 '17 at 13:05

1 Answers1

8

I find solution:

<ItemGroup>
    <ReportFiles Include="..\Reports\**\*.rdlc">
        <Path>\Reports</Path>
    </ReportFiles>
</ItemGroup>

<Target Name="PrepublishScript"
        BeforeTargets="PrepareForPublish">
    <Copy SourceFiles="@(ReportFiles)"
          DestinationFolder="$(PublishDir)\%(Path)"
          SkipUnchangedFiles="false" />
</Target>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Igor
  • 381
  • 3
  • 17
  • Thanks. For other people, just be careful with the double dots of the include. If your folder is at the project level, you need to use only one. – Augusto Barreto Nov 14 '18 at 16:04