Copy all files and folders using msbuild

2019-01-10 12:16发布

Just wondering if someone could help me with some msbuild scripts that I am trying to write. What I would like to do is copy all the files and sub folders from a folder to another folder using msbuild.

{ProjectName}
      |----->Source
      |----->Tools
              |----->Viewer
                       |-----{about 5 sub dirs}

What I need to be able to do is copy all the files and sub folders from the tools folder into the debug folder for the application. This is the code that I have so far.

 <ItemGroup>
<Viewer Include="..\$(ApplicationDirectory)\Tools\viewer\**\*.*" />
 </ItemGroup>

<Target Name="BeforeBuild">
        <Copy SourceFiles="@(Viewer)" DestinationFolder="@(Viewer->'$(OutputPath)\\Tools')" />
  </Target>

The build script runs but doesn't copy any of the files or folders.

Thanks

8条回答
我命由我不由天
2楼-- · 2019-01-10 12:50

I'm kinda new to MSBuild but I find the EXEC Task handy for situation like these. I came across the same challenge in my project and this worked for me and was much simpler. Someone please let me know if it's not a good practice.

<Target Name="CopyToDeployFolder" DependsOnTargets="CompileWebSite">
    <Exec Command="xcopy.exe  $(OutputDirectory) $(DeploymentDirectory) /e" WorkingDirectory="C:\Windows\" />
</Target>
查看更多
对你真心纯属浪费
3楼-- · 2019-01-10 12:52

Did you try to specify concrete destination directory instead of

DestinationFolder="@(Viewer->'$(OutputPath)\\Tools')" ? 

I'm not very proficient with advanced MSBuild syntax, but

@(Viewer->'$(OutputPath)\\Tools') 

looks weird to me. Script looks good, so the problem might be in values of $(ApplicationDirectory) and $(OutputPath)

EDIT:

Here is a blog post that might be useful:

How To: Recursively Copy Files Using the Task

查看更多
登录 后发表回答