1

How do I copy a single file using the CopyFiles Task without copying its entire enclosing folder hierarchy? When the following task executes:

    - task: CopyFiles@2
      inputs:
        Contents: '**/dataSettings.json' 
        TargetFolder: '$(Build.ArtifactStagingDirectory)/$(buildConfiguration)/Nop.Web/App_Data'

It copies the entire folder hierarchy and the file 'src/Presentation/Nop.Web/App_Data/' to the target folder:

Nop.Web/App_Data/src/Presentation/Nop.Web/App_Data/dataSettings.json

I want it to copy the file to the following location:

Nop.Web/App_Data/dataSettings.json

If I change the Contents to dataSettings.json the file cannot be copied.

I am open to using another task to achieve the same result.

ATL_DEV
  • 9,256
  • 11
  • 60
  • 102
  • the flattenFolders parameter should work perfectly. You can accept below answer if it fixed above issue. – Levi Lu-MSFT Mar 02 '21 at 02:13
  • 2
    I would like to know why Azure DevOps build tasks are so convoluted. The reference documentation is terrible. I did see the option to flatten folders, but it was unclear what what it does. Why does it work differently from how a standard copy command would work? There are few examples usages and all of the options have one line descriptions. To make matters worse, figuring it out through trial and error is extremely painful since you have to wait for the build to complete to verify the results. If this doesn't improve, I will have to recommend another build system to my employer. – ATL_DEV Mar 02 '21 at 02:57

1 Answers1

1

You should set the flattenFolders parameter of the CopyFiles@2 task to true. It is false by default. According to the docs:

It flattens the folder structure and copies all files into the specified target folder

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139