Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy one file in target directory on deploy from visual studio team services

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?

like image 851
Georgy Grigoryev Avatar asked Jan 04 '16 08:01

Georgy Grigoryev


People also ask

How do I move files from one directory to another on Azure Devops?

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.

How do I copy a file from one directory to another in VB net?

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.

What is copy to output directory C#?

"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.


4 Answers

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:

  1. Add a "Copy Files" step to copy "project.exe". Settings like following: enter image description here
  2. Add a "Copy Files" step to copy "SomeScripts" folder. Settings like following: enter image description here
  3. Add a "Copy and Publish Build Artifacts" step to copy these files to "drop". Settings like following: enter image description here

Now you should get the things like following in drop folder:

Project.exe
SomeScripts
    script.ps1
like image 134
Eddie Chen - MSFT Avatar answered Oct 18 '22 04:10

Eddie Chen - MSFT


"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

like image 32
igor_1024 Avatar answered Oct 18 '22 06:10

igor_1024


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.

like image 41
Pascal Berger Avatar answered Oct 18 '22 04:10

Pascal Berger


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

like image 20
thomasgalliker Avatar answered Oct 18 '22 05:10

thomasgalliker