3

Essentially, what I want to do is use a wildcard for a directory.

The post build event is on a PageComponents project:

PageComponents
    WidgetTemplates
        WidgetTemplate1
            Usercontrol1
        WidgetTemplate2
            Usercontrol2

And I want to copy all user controls to a Web project, but to a different relative location:

Web
    CtrlPresentation
        Usercontrol1
        Usercontrol2

I tried to wildcard the WidgetTemplates directory:

xcopy "$(ProjectDir)WidgetTemplates\*\*.ascx" "$(SolutionDir)Client.Web\CtrlPresentation" /y /s

But this fails all together. So then I tried the following:

xcopy "$(ProjectDir)WidgetTemplates\*.ascx" "$(SolutionDir)Client.Web\CtrlPresentation" /y /s

But this copies each individual WidgetTemplate folder over as well.

Is there a way to achieve what I'm trying to do?

Jeremy Wiggins
  • 7,239
  • 6
  • 41
  • 56
  • Jeremy - did you solve this? I'm trying to solve a very similar problem. – itsmatt May 08 '12 at 15:18
  • @itsmatt - No, unfortunately not. I went with the manual approach of just adding an `xcopy` for each directory I wanted to copy. I only ended up with about a dozen or so, so it wasn't a huge issue. – Jeremy Wiggins May 08 '12 at 16:45
  • Based on the documentation, it seems like you'd want to omit the `/s`. [link](https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true). **/s : Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory.**. Have you tried running the xcopy command in cmd just to amek sure it's doing what you expect? – Nick Molyneux Jan 13 '17 at 17:51

1 Answers1

0

Try using a Task.

<ItemGroup>
    <MySources Include="$(ProjectDir)WidgetTemplates\**\*.ascx" />
</ItemGroup>
<Target Name="CopyOver">
    <Copy SourceFiles="@(MySources)" DestinationFiles="@(MySources->'$(SolutionDir)Client.Web\CtrlPresentation\%(FileName)%(Extension)')">
</Target>

and use this target after your Build

<BuildDependsOn>
    $(BuildDependsOn);
    CopyOver
</BuildDependsOn>
Daniel
  • 49
  • 6