5

I want to copy all files recursivly with given file extensions after the build process succeeds.

Robocopy

ROBOCOPY %source% %destination% /S *.as?x *.xls? *.mrt

xcopy

xcopy .\*.as?x %destination% /SY
xcopy .\*.xls? %destination% /SY
xcopy .\*.mrt %destination% /SY

I have tried to insert both possibilities in the post build section in visual studio. RoboCopy exits with error: Error 1 The command "ROBOCOPY source destination /S *.as?x *.xls? *.mrt" exited with code 1. Some files where copied but to the wrong folder (_PublishedWebsites).

xcopy also copy to the wrong directory (_PublishedWebsites) and also does not copy all files.

In the command line both commands work as expected.

Update

I have updated my robocopy command:

ROBOCOPY $(MSBuildProjectDirectory) $(MSBuildProjectDirectory)\..\..\..\EDP\Web\Modules\Invoice\Web /S *.as?x *.xls? *.mrt

Now the files are copied to the correct location, but the return code of robocopy causes an visual studio error.

Here a solution with help of this:

call ROBOCOPY $(MSBuildProjectDirectory) $(MSBuildProjectDirectory)\..\..\..\EDP\Web\Modules\Invoice\Web /S *.as?x *.xls? *.mrt
if %errorlevel% leq 1 exit 0 else exit %errorlevel%

Preferred solution

<ItemGroup>
    <SourceFiles Include="$(MSBuildProjectDirectory)\**\*.js"/>
    <SourceFiles Include="$(MSBuildProjectDirectory)\**\*.html"/>
    <SourceFiles Include="$(MSBuildProjectDirectory)\**\*.css*"/>
    <SourceFiles Include="$(MSBuildProjectDirectory)\**\*.png"/>
    <SourceFiles Include="$(MSBuildProjectDirectory)\**\*.as?x"/>
</ItemGroup>

<Target Name="AfterBuild">
    <Copy
       SourceFiles="@(SourceFiles)"
       DestinationFiles="@(SourceFiles->'%(MSBuildProjectDirectory)..\..\..\EDP\Web\Modules\DMS\Web\%(RecursiveDir)%(Filename)%(Extension)')"
    />
</Target>
Community
  • 1
  • 1
Marko
  • 1,291
  • 1
  • 21
  • 37

0 Answers0