如何使MSBuild将所有标记为“内容"的文件复制到文件夹中,并保留文件夹结构? [英] How can I get MSBuild to copy all files marked as Content to a folder, preserving folder structure?
问题描述
作为我的解决方案构建的一部分,我想将所有内容"文件(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.
蝙蝠文件语法建议不能解决该问题-仅适用纯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屋!