Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get MSBuild to copy all files marked as Content to a folder, preserving folder structure?

Tags:

msbuild

As part of my solution build, I want to copy all "Content" files (asp?x etc) to another folder. Since these are so clearly tagged in the project, I thought there must be an easy way to copy these instead of writing my own post-build step with xcopy. Unfortunately I haven't been able to figure this out - this msbuild thing is incompatible with my brain. I just want a step like but can't figure out the syntax to use.

Bat file syntax suggestions would not be an answer to this question - only pure msbuild solutions apply

Thanks, Per

like image 465
Pelle Avatar asked Oct 04 '11 05:10

Pelle


1 Answers

You can easily do this by the following:

<PropertyGroup>
  <DestFolder>..\Copy\</DestFolder>
</PropertyGroup>

<Target Name="CopyContentFiles">
  <Copy SourceFiles="@(Content)"
        DestinationFiles="@(Content->'$(DestFolder)%(RelativeDir)%(Filename)%(Extension)')"/>
</Target>

If you want to execute this as a post-build steps then you can just add AfterTargets="Build" for example:

<PropertyGroup>
  <DestFolder>..\Copy\</DestFolder>
</PropertyGroup>

<Target Name="CopyContentFiles" AfterTargets="Build">
  <Copy SourceFiles="@(Content)"
        DestinationFiles="@(Content->'$(DestFolder)%(RelativeDir)%(Filename)%(Extension)')"/>
</Target>
like image 135
Sayed Ibrahim Hashimi Avatar answered Oct 23 '22 13:10

Sayed Ibrahim Hashimi