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
  • 704,970
  • 168
  • 1,303
  • 1,425
praveen
  • 85
  • 11

1 Answers1

0

Try to use your own MSBuild targets instead of post build event.

The target we need to extend is called CopyAllFilesToSingleFolder. This target has a dependency property, PipelinePreDeployCopyAllFilesToOneFolderDependsOn, that we can tap into and inject our own target. So we will create a target named CustomCollectFiles and inject that into the process. We achieve this with the following (remember after the import statement).

<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 in the Include attribute told it to pick up all the files in that folder and any folder underneath it. Then I use this item to populate the FilesForPackagingFromProject item. This is the item that MSDeploy actually uses to add extra files. Also notice that I declared the metadata DestinationRelativePath value. This will determine the relative path that it will be placed in the package. I used the statement Extra Files%(RecursiveDir)%(Filename)%(Extension) here. What that is saying is to place it in the same relative location in the package as it is under the Extra Files folder.

Please refer this SO Thread for more information.

HariKrishnaRajoli-MT
  • 3,193
  • 1
  • 4
  • 18