How do I exclude the contents of a directory but not the directory itself in MSBuild

风流意气都作罢 提交于 2019-12-12 05:58:00

问题


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\**\*.*" />

it will exclude the ImageCache directory itself. So how do I keep the directory? Thanks in advance?


回答1:


I'm afraid you must do this in two lines :

<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\ImageCache\**\*.*" />
<IncludeFromBuild Include="$(SourceWebPhysicalPath)\ImageCache\" />

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>


来源:https://stackoverflow.com/questions/3804383/how-do-i-exclude-the-contents-of-a-directory-but-not-the-directory-itself-in-msb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!