none
Copy a folder after build

    Question

  • I'm trying to copy a folder from my Project folder to my output folder after I build my application. I've tried to use the post-build build event but it doesn't work because it copies the contents of the folder instead of the folder itself.

    Can anyone offer any suggestions? I'm completely new to this MSBuild thing so foolproof answers are appreciated.


    Mods - Please do not mark my posts as answered. It is extremely rude. You have no idea if you've answered my question.
    Wednesday, June 03, 2009 2:15 PM

Answers

  • Do you want the folder + contents? I'm guessing you are getting all contents flat with the output.

    Add something similar to this in your csproj file

        <Target Name="AfterBuild">
            <ItemGroup>
                <MyFiles Include="Folder1\*.*"/>
            </ItemGroup>
            <Microsoft.Build.Tasks.Copy SourceFiles="@(MyFiles)" DestinationFolder="$(OutputPath)\Folder1"/>
        </Target>
    • Marked as answer by BLeg Friday, June 05, 2009 3:08 PM
    Wednesday, June 03, 2009 6:48 PM

All replies

  • Do you want the folder + contents? I'm guessing you are getting all contents flat with the output.

    Add something similar to this in your csproj file

        <Target Name="AfterBuild">
            <ItemGroup>
                <MyFiles Include="Folder1\*.*"/>
            </ItemGroup>
            <Microsoft.Build.Tasks.Copy SourceFiles="@(MyFiles)" DestinationFolder="$(OutputPath)\Folder1"/>
        </Target>
    • Marked as answer by BLeg Friday, June 05, 2009 3:08 PM
    Wednesday, June 03, 2009 6:48 PM
  • and if you need recursion, use something similar to this

        <Target Name="AfterBuild">
            <ItemGroup>
                <MyFiles Include="Folder1\**\*.*" />
            </ItemGroup>
            <Microsoft.Build.Tasks.Copy SourceFiles="@(MyFiles)"  DestinationFiles="@(MyFiles->'$(OutputPath)\Folder1\%(RecursiveDir)%(Filename)%(Extension)')"/>
        </Target>
    Wednesday, June 03, 2009 6:51 PM
  • Excellent...

    Thanks a lot.

    PS, I used it in my .vbproj file ;)
    Mods - Please do not mark my posts as answered. It is extremely rude. You have no idea if you've answered my question.
    Friday, June 05, 2009 3:07 PM