Search code examples
workflow-foundationtfsbuildbuild-server

Copy build outputs from multiple projects to same folder


I have a Visual Studio 2013 Solution with custom project types provided by a plugin. These projects do not support specifying the build outputs folder or post build events. I need to copy the build outputs from the outputs location of each project to a single bin folder such that they can be uploaded to a drop location in TFS. How would I write a batch script or similar to copy the outputs from

\SolutionDir\Project1\Debug\Win32\*
\SolutionDir\Project2\Debug\Win32\*
...

to

\SolutionDir\bin\Debug\Win32\*

Bearing in mind that some projects depend on others and therefore the same .dll may be present in multiple locations. It doesn't matter which I keep. I tried something like

for /f "tokens=*" %a in ('dir *.dll *.exe /b /s /a-d') do copy "%a" "bin" /y

But that does not preserve the \Debug\Win32 folder structure


Solution

  • I managed to work it out with the help of a batch script which I called CopyBins.bat. It is not particularly elegant, but here it is;

    dir /b /s /ad | find "\%1\" > folders.txt
    for /f "tokens=*" %%a in ('cat folders.txt') do xcopy /s /y "%%a" %1\
    del folders.txt
    

    Then I can execute it by calling

    CopyBins Debug
    

    Bear in mind that I can't just execute

    for /f "tokens=*" %a in ('dir /b /s /ad | find "\Debug\"') do xcopy /s /y "%a" Debug\
    

    Because I get the error

    | was unexpected at this time.
    

    If anybody has a better solution I would like to hear it...