0

I have an Azure function which has an assets folder (needed for something) which contains some files including .pdb, .dll, .exe etc.

When I publish the project using the Visual Studio Publish, it is removing the dlls from that folder.

I've tried adding this to the csproject but still they did not get copied

 <ItemGroup>
    <Content Include="assets\**\*">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        <CopyToPublishDirectory>Always</CopyToPublishDirectory>
    </Content>
</ItemGroup>

Tried doing a post build copy event as well but that didn't work either

xcopy "$(ProjectDir)assets\*.*" "$(TargetDir)\assets" /Y /I /E 

Folder Structure Files in output directory

The left image contains the structure of the folders and the dlls that the solution has but when the publish happens I don't see the dlls in the published folder.

How do I get all the files/folders in the assets folder to be copied to the publish folder?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
praveen
  • 95
  • 15

1 Answers1

0

Instead of post build event, try using your own MSBuild targets.

We must extend a target called CopyAllFilesToSingleFolder. PipelinePreDeployCopyAllFilesToOneFolderDependsOn is a dependence property of this target that we can use to inject our own target into. In order to inject CustomCollectFiles into the process, we will first create the target.

<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include="..\Extra Files\**\*" />

    <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
      <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

Create the item _CustomFiles and instruct it to pick up every file in that folder and any folders below it in the Include attribute. The FilesForPackagingFromProject item is then filled out using this item. In order to add additional files, MSDeploy actually uses this item. Also take note of the metadata DestinationRelativePath value I declared. This will determine where it will be located within the package relative to other objects. Extra Files%(RecursiveDir)%(Filename)%(Extension) is the statement I used in this instance. It should be put in the same relative spot in the package where it is in the Extra Files folder, according to what that means.

Please refer this SO Thread for more information.

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15