如何让 MSBuild 将标记为内容的所有文件复制到文件夹中,同时保留文件夹结构? [英] How can I get MSBuild to copy all files marked as Content to a folder, preserving folder structure?

查看:20
本文介绍了如何让 MSBuild 将标记为内容的所有文件复制到文件夹中,同时保留文件夹结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为解决方案构建的一部分,我想将所有内容"文件(asp?x 等)复制到另一个文件夹.由于这些在项目中标记得很清楚,我认为必须有一种简单的方法来复制这些,而不是用 xcopy 编写我自己的构建后步骤.不幸的是,我无法弄清楚这一点 - 这个 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 文件语法建议不是这个问题的答案 - 只有纯 msbuild 解决方案适用

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

谢谢,每

推荐答案

您可以通过以下方式轻松做到这一点:

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>

如果您想将此作为构建后步骤执行,则只需添加 AfterTargets="Build" 例如:

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>

这篇关于如何让 MSBuild 将标记为内容的所有文件复制到文件夹中,同时保留文件夹结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆