AfterPublish 目标不起作用
在我发布 Web 应用程序项目后,世界上最简单的任务(见下文)并未被执行。知道为什么吗?
<Target Name="AfterPublish">
<Copy SourceFiles="C:\A.txt" DestinationFiles="C:\B.txt" />
</Target>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
注意:以下内容适用于 VS2010 以及在“构建/发布 {projectname}”对话框中选择“Web 部署”发布方法来发布 Web 应用程序项目。
Julien Hoarau 的正确之处在于“Publish”不是在上述情况下调用的 msbuild 目标的名称;实际目标名称是“MSDeployPublish”。
因此,您必须定义一个 "Target" 元素,其 "AfterTarget" 属性值设置为 "MSDeployPublish" - "Name" 属性的值值并不重要(只要它在目标名称中是唯一的)。
操作方法如下:
标记之前添加
元素;为“CustomPostPublishAction”选择一个名称。
元素。示例:
注意:
元素的一般文档,请参阅 http:// msdn.microsoft.com/en-us/library/t50z2hka.aspxNote: 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's correct in that "Publish" is NOT the name of the msbuild target invoked in the above case; the actual target name is "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).
Here's how to do it:
</Project>
tag, add a<Target Name="CustomPostPublishAction" AfterTargets="MSDeployPublish">
element; pick a name of your choice for "CustomPostPublishAction".<Exec Command="..." />
element.Example:
Note:
<Target>
element in general, see http://msdn.microsoft.com/en-us/library/t50z2hka.aspxVisual Studio 2013。将 Web 应用程序发布到文件系统。
注意:确保构建日志记录至少设置为“详细”。在“工具”->“工具”下查找它选项->项目和解决方案 ->构建并运行 -> MSBuild 输出详细信息。如果您想调查实际发布之前最后运行的构建目标,诊断也可以。
Visual Studio 2013. Publish Web application to file system.
Note: Make sure that build logging is set to at least to Detailed. Look for it under Tools -> Options -> Projects and Solutinos -> Build and Run -> MSBuild output verbosity. Diagnostic is also fine if you want to investigate which build target was last run before actual publish.
这似乎适用于 Visual Studio 2019
This seems to work in Visual Studio 2019
启动 MSBuild 并详细了解您的目标被忽略的原因:
AfterPublish
在Publish
目标之后调用,但Publish
> 不是您发布 Web 应用程序时调用的目标。Publish
是发布ClickOnce 应用程序的目标。您必须找到在 Visual Studio 中调用
Publish
时使用的目标,它可能是Package
、WebPublish
...<Import ... />
Launch MSBuild with detailed verbosity to see why your target is ignored :
AfterPublish
is called afterPublish
target, butPublish
is not the target called when you publish a web application.Publish
is the target for publishing ClickOnce application.You'll have to find the target used when you call
Publish
in Visual Studio, it could bePackage
,WebPublish
...我现在有点懒惰去找出混乱的目标,以找到适合基于文件的发布(您可能对此感兴趣)的目标。同时您可以做的是在 *.pubxml 文件中定义 AfterBuild 目标。
...
我建议还关闭属性“DeleteExistingFiles”,因为如果您将文件复制到正在发布的目录中,它会在发布过程中的某个地方进行清理。
I'm a little lazy right now to figure out the mess of targets to find the right one for a file-based publish (which you might be interested in). What you can do in the meantime is defining an AfterBuild target in the *.pubxml file.
...
I recommend also turning off the property "DeleteExistingFiles" because if you copy files into the directories being published, it does a clean somewhere during the publishing process.