I'm using VSTS as a build server, and while building I want to copy the bin folder contents to the root of the target, and also custom files from another folder to this target. MSDN suggests I use a minimatch pattern, but it's copying files with the subdirectory structure. I'm not interested in restoring the structure.
For example, I am getting this folder structure:
Project
MyProjectFiles
bin
x86 (it's build configuration)
Project.exe
Other project files
Project.sln
SomeScrips
script1.ps1
But I want to receive this folder structure:
Project.exe
SomeScripts
script.ps1
Which minimatch pattern can I use for my requirements?
In Source Control Explorer, select the item that you want to move, open its shortcut menu, and choose Move. In the Move dialog box, either manually type the destination for the item in the To box, or choose Browse to use the Browse for Folder dialog box. Choose OK.
Use the CopyFile method to copy a file, specifying a source file and the target directory. The overwrite parameter allows you to specify whether or not to overwrite existing files.
"Copy to Output Directory" is the property of the files within a Visual Studio project, which defines if the file will be copied to the project's built path as it is. Coping the file as it is allows us to use relative path to files within the project.
You need to specify the copy root if you want to copy files only without folder structure. Since the project.exe is in a different path with script.ps1 file, you need to copy them in different copy task.
Following the steps below:
Now you should get the things like following in drop folder:
Project.exe
SomeScripts
script.ps1
"Flatten Folders" option in "Advanced" section of "Copy Files" step.
If you are using TFS Online (Visual Studio Online) and don't need to copy the folder structure use "Flatten Folders" option in "Advanced" section of "Copy Files" step in your build definition
With the new web based build system you can use multiple patterns in a single step. Therefore you can do something like this for your case:
Project\bin\x86\Release\project.exe
SomeScripts\**\*
Or if you have the build platform and configuration in a variable (eg. BuildPlatform
/ BuildConfiguration
) which you also use in the build step you could use them in the pattern:
Project\bin\$(BuildPlatform)\$(BuildConfiguration)\project.exe
SomeScripts\**\*
If you want the project.exe
to be in the root instead of the structure you need to use a Copy Task
to stage your files in the desired structure first. You can use $(Build.StagingDirectory)
as a target for this. Afterwards use the Publish task with $(Build.StagingDirectory)
as copy root and publish everything from this root to the drop.
The "flattenFolders" option is also available as a YAML task parameter. The following code excerpt shows a CopyFiles@2 task which copyies the build output to the $(Build.ArtifactStagingDirectory). When I specify the option flattenFolders: true
the nested folder structure bin\release\...\My.exe
is flattened, means the exe files is copied to the root of $(Build.ArtifactStagingDirectory).
- task: CopyFiles@2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: |
**\bin\$(BuildConfiguration)\**\*.exe
TargetFolder: '$(Build.ArtifactStagingDirectory)'
flattenFolders: true
Further documentation concerning the CopyFiles task can be found here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=vsts&tabs=yaml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With