如何在MSBuild中排除目录的内容而不排除目录本身 [英] How do I exclude the contents of a directory but not the directory itself in MSBuild
问题描述
我正在使用Web Deployment Project 2008构建我的Web应用程序.我想从构建中排除几个文件夹的内容,但保留空白目录本身.但是,如果我这样做
I'm using a Web Deployment Project 2008 to build my web application. I'd like to exclude the contents of several folders from the build but keep the blank directory itself. However, if I do this
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\ImageCache\**\*.*" />
它将排除ImageCache目录本身.那么如何保留目录?预先感谢?
it will exclude the ImageCache directory itself. So how do I keep the directory? Thanks in advance?
推荐答案
恐怕您必须分两行执行此操作:
I'm afraid you must do this in two lines :
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\ImageCache\**\*.*" />
<IncludeFromBuild Include="$(SourceWebPhysicalPath)\ImageCache\" />
但是,由于The "Copy" task does not support copying directories
,因此无法正常工作.
因此,我建议您像以前一样排除文件,并在AfterMerge目标中创建一个空目录:
But that could not work because The "Copy" task does not support copying directories
.
Thus, what I suggest is that you exclude the files like you did and create an empty directory in the AfterMerge target :
<ItemGroup>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\ImageCache\**\*.*" />
<ItemGroup>
<...>
<Target Name="AfterMerge">
<MakeDir Directories="$(SourceWebPhysicalPath)\ImageCache" />
</Target>
这篇关于如何在MSBuild中排除目录的内容而不排除目录本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!