AfterPublish目标不起作用 [英] AfterPublish target not working
问题描述
发布Web应用程序项目后,世界上最简单的任务(请参见下文)未执行.知道为什么吗?
World's simplest task (see below) is not being executed after I publish my web application project. Any idea why?
<Target Name="AfterPublish">
<Copy SourceFiles="C:\A.txt" DestinationFiles="C:\B.txt" />
</Target>
推荐答案
注意:以下内容适用于VS2010和使用在构建/发布{projectname}"对话框中选择的"Web Deploy"发布方法发布Web应用程序项目
Note: The following applies to VS2010 and publishing web-application projects with the "Web Deploy" publish method selected in the 'Build/Publish {projectname}' dialog.
Julien Hoarau的正确之处在于发布"不是上述情况下调用的msbuild目标的名称;实际的目标名称是"MSDeployPublish" .
Julien Hoarau's correct in that "Publish" is NOT the name of the msbuild target invoked in the above case; the actual target name is "MSDeployPublish".
因此,您必须定义一个"Target" 元素,该元素的"AfterTarget" 属性值设置为"MSDeployPublish" -名称"属性的值无关紧要(只要在目标名称中唯一)即可.
Therefore, you have to define a "Target" element whose "AfterTarget" attribute's value is set to "MSDeployPublish" - the "Name" attribute's value does not matter (as long as it's unique among target names).
方法如下:
- 在文本/XML编辑器中打开项目文件(例如* .csproj),然后在结束
</Project>
标记之前,添加一个<Target Name="CustomPostPublishAction" AfterTargets="MSDeployPublish">
元素;为"CustomPostPublishAction"选择一个您选择的名称. - 添加一个执行所需动作的所谓Task子元素;例如,要添加要传递给cmd.exe的命令,请使用
<Exec Command="..." />
元素.
- Open the project file (e.g. *.csproj) in a text/XML editor and, just before the closing
</Project>
tag, add a<Target Name="CustomPostPublishAction" AfterTargets="MSDeployPublish">
element; pick a name of your choice for "CustomPostPublishAction". - Add a so-called Task child element that performs the desired action; for instance, to add a command to be passed to cmd.exe, use an
<Exec Command="..." />
element.
示例:
<Target Name="CustomPostPublishActions" AfterTargets="MSDeployPublish" >
<Exec Command="echo Post-PUBLISH event: Active configuration is: $(ConfigurationName)" />
</Target>
注意:
- 在命令字符串中,使用XML实体(?)引用代替可能破坏XML解析的字符,例如& gt"代替<".
- 有关一般
<Target>
元素的文档,请参见 http://msdn.microsoft.com /en-us/library/t50z2hka.aspx - 此处的任务元素参考: http://msdn.microsoft.com/en-us/library /7z253716.aspx
- 通常,如果需要确定Visual Studio 2010实际调用的msbuild.exe目标的名称,请执行以下操作:
- 转到工具/选项...",项目和解决方案/构建并运行",从标有"MSBuild项目构建输出详细程度"的下拉列表中选择详细"(或更多信息,诊断"). li>
- 运行构建/发布操作后,例如生成/发布,检查输出"窗口中是否出现字符串完成构建目标"的最后,以确定已调用的顶级目标.
- In command strings, use XML entity(?) references in place of characters that would break XML parsing, e.g. ">" in place of "<".
- For documentation of the
<Target>
element in general, see http://msdn.microsoft.com/en-us/library/t50z2hka.aspx - Task-elements reference here: http://msdn.microsoft.com/en-us/library/7z253716.aspx
- In general, if you need to determine the name of the msbuild.exe target that is actually invoked by Visual Studio 2010, do the following:
- Go to Tools/Options..., Project and Solutions/Build and Run, select 'Detailed' (or, for even more information, 'Diagnostic') from the dropdown list labeled 'MSBuild project build output verbosity.
- After running the build/publish action, e.g. Build/Publish, examine the Output window for the last occurrence of the string "Done building target" to determine the top-level target that was invoked.
这篇关于AfterPublish目标不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!