如何使用msbuild/web部署项目删除多个文件?
我对 msbuild 在 VS2008 Web 部署项目中的表现有一个奇怪的问题,并且想知道为什么它似乎随机表现不佳。
我需要从部署文件夹中删除一些仅应存在于我的开发环境中的文件。 这些文件是 Web 应用程序在开发/测试期间生成的,不包含在我的 Visual Studio 项目/解决方案中。
我使用的配置如下:
<!-- Partial extract from Microsoft Visual Studio 2008 Web Deployment Project -->
<ItemGroup>
<DeleteAfterBuild Include="$(OutputPath)data\errors\*.xml" /> <!-- Folder 1: 36 files -->
<DeleteAfterBuild Include="$(OutputPath)data\logos\*.*" /> <!-- Folder 2: 2 files -->
<DeleteAfterBuild Include="$(OutputPath)banners\*.*" /> <!-- Folder 3: 1 file -->
</ItemGroup>
<Target Name="AfterBuild">
<Message Text="------ AfterBuild process starting ------" Importance="high" />
<Delete Files="@(DeleteAfterBuild)">
<Output TaskParameter="DeletedFiles" PropertyName="deleted" />
</Delete>
<Message Text="DELETED FILES: $(deleted)" Importance="high" />
<Message Text="------ AfterBuild process complete ------" Importance="high" />
</Target>
我遇到的问题是,当我构建/重建 Web 部署项目时,它“有时”会删除所有文件,但有时它不会删除任何内容! 或者,它将仅删除“DeleteAfterBuild”项目组中三个文件夹中的一两个。 构建过程决定是否删除文件的时间似乎没有一致性。
当我编辑配置以仅包含文件夹 1(例如)时,它会正确删除所有文件。 然后添加文件夹 2 和 3,它开始删除我想要的所有文件。 然后,我会随机重建该项目,并且不会删除任何文件!
我尝试将这些项目移动到 ExcludeFromBuild 项目组(这可能是它应该在的位置),但它给了我同样不可预测的结果。
有人经历过这个吗? 难道我做错了什么? 为什么会出现这种情况?
I have an odd issue with how msbuild is behaving with a VS2008 Web Deployment Project and would like to know why it seems to randomly misbehave.
I need to remove a number of files from a deployment folder that should only exist in my development environment. The files have been generated by the web application during dev/testing and are not included in my Visual Studio project/solution.
The configuration I am using is as follows:
<!-- Partial extract from Microsoft Visual Studio 2008 Web Deployment Project -->
<ItemGroup>
<DeleteAfterBuild Include="$(OutputPath)data\errors\*.xml" /> <!-- Folder 1: 36 files -->
<DeleteAfterBuild Include="$(OutputPath)data\logos\*.*" /> <!-- Folder 2: 2 files -->
<DeleteAfterBuild Include="$(OutputPath)banners\*.*" /> <!-- Folder 3: 1 file -->
</ItemGroup>
<Target Name="AfterBuild">
<Message Text="------ AfterBuild process starting ------" Importance="high" />
<Delete Files="@(DeleteAfterBuild)">
<Output TaskParameter="DeletedFiles" PropertyName="deleted" />
</Delete>
<Message Text="DELETED FILES: $(deleted)" Importance="high" />
<Message Text="------ AfterBuild process complete ------" Importance="high" />
</Target>
The problem I have is that when I do a build/rebuild of the Web Deployment Project it "sometimes" removes all the files but other times it will not remove anything! Or it will remove only one or two of the three folders in the DeleteAfterBuild item group. There seems to be no consistency in when the build process decides to remove the files or not.
When I've edited the configuration to include only Folder 1 (for example), it removes all the files correctly. Then adding Folder 2 and 3, it starts removing all the files as I want. Then, seeming at random times, I'll rebuild the project and it won't remove any of the files!
I have tried moving these items to the ExcludeFromBuild item group (which is probably where it should be) but it gives me the same unpredictable result.
Has anyone experienced this? Am I doing something wrong? Why does this happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在脚本加载时且在
处理之前进行评估。似乎有不止一种方法可以正确执行此操作 -
将
包含在
中,并且应该在正确的时间。 这将适用于 MS-Build v3.5+使用
生成项目列表示例构建脚本 -
解释为什么删除过程生成“不可预测”的结果 -
@(DeleteAfterBuild)
将在没有文件的情况下进行评估,因为$(OutputPath)
文件夹中不存在这些文件,并且不会删除作为一部分的任何文件AfterBuild
目标@(DeleteAfterBuild)
将使用$(OutputPath)
文件夹中的所有预期文件进行评估,并将这些文件作为AfterBuild
目标的一部分删除参考资料:
如何:动态创建项目组,
延迟评估 MSBUILD 中的项目文件
The
<ItemGroup>
is evaluated when the script loads and before the<Target>
has been processed.There appears to be more than one way to do this correctly -
Include the
<ItemGroup>
inside of the<Target>
and it should be evaluated at the correct time. This will work with MS-Build v3.5+Use
<CreateItem>
to generate the item listExample build script for this -
To explain why the delete process was generating 'unpredictable' results -
@(DeleteAfterBuild)
will evaluate with no files as the files don't exist in the$(OutputPath)
folder and will not delete any files as part of theAfterBuild
target@(DeleteAfterBuild)
will evaluate with all the expected files in the$(OutputPath)
folder and will remove the files as part of theAfterBuild
targetReference material:
How To: Create Item Groups on the Fly,
Delayed evaluation of items in MSBUILD file
我意识到这个问题已经得到了回答,但我想我应该加 5 美分。 对于 Web 部署项目,无需使用提供的目标,只需添加包含 ExcludeFromBuild 元素的项目组即可。 我提供了部署项目文件底部的相关部分以供参考。
I realise this has already been answered but I thought I would add my 5 cents. For a Web Deployment project there's no need to use the provided targets, just add an item group containing ExcludeFromBuild elements. I've provided the relevant section from the bottom of my deployment project file for reference.