AfterPublish 目标不起作用

发布于 2024-09-16 04:55:49 字数 196 浏览 7 评论 0原文

在我发布 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

世界等同你 2024-09-23 04:55:49

注意:以下内容适用于 VS2010 以及在“构建/发布 {projectname}”对话框中选择“Web 部署”发布方法来发布 Web 应用程序项目。

Julien Hoarau 的正确之处在于“Publish”不是在上述情况下调用的 msbuild 目标的名称;实际目标名称是“MSDeployPublish”

因此,您必须定义一个 "Target" 元素,其 "AfterTarget" 属性值设置为 "MSDeployPublish" - "Name" 属性的值值并不重要(只要它在目标名称中是唯一的)。

操作方法如下:

  • 在文本/XML 编辑器中打开项目文件(例如 *.csproj),然后在结束 标记之前添加 元素;为“CustomPostPublishAction”选择一个名称。
  • 添加一个所谓的 Task 子元素来执行所需的操作;例如,要添加要传递给 cmd.exe 的命令,请使用 元素。

示例:

<Target Name="CustomPostPublishActions" AfterTargets="MSDeployPublish" >
    <Exec Command="echo Post-PUBLISH event: Active configuration is: $(ConfigurationName)" />
</Target>

注意:

  • 在命令字符串中,使用 XML 实体 (?) 引用代替会破坏 XML 解析的字符,例如用“>”代替“<”。
  • 有关 元素的一般文档,请参阅 http:// msdn.microsoft.com/en-us/library/t50z2hka.aspx
  • 此处的任务元素参考:http://msdn.microsoft.com/en-us/library/7z253716.aspx
  • 一般来说,如果您需要确定 Visual Studio 2010 实际调用的 msbuild.exe 目标的名称,请执行以下操作:下列:
    • 转至“工具/选项...”、“项目和解决方案/生成并运行”,从标有“MSBuild 项目生成输出详细信息”的下拉列表中选择“详细”(或者,如需了解更多信息,请选择“诊断”)。
    • 运行构建/发布操作(例如构建/发布)后,检查“输出”窗口中最后一次出现的字符串“完成构建目标”,以确定调用的顶级目标。

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'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:

  • 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.

Example:

<Target Name="CustomPostPublishActions" AfterTargets="MSDeployPublish" >
    <Exec Command="echo Post-PUBLISH event: Active configuration is: $(ConfigurationName)" />
</Target>

Note:

  • 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.
拥抱没勇气 2024-09-23 04:55:49

Visual Studio 2013。将 Web 应用程序发布到文件系统。

  <Target Name="Moose" AfterTargets="GatherAllFilesToPublish" >
    <Message Importance="high" Text="***Moooooooooooooooose***$(WPPAllFilesInSingleFolder)***$(TargetDir)" />
  </Target>

注意:确保构建日志记录至少设置为“详细”。在“工具”->“工具”下查找它选项->项目和解决方案 ->构建并运行 -> MSBuild 输出详细信息。如果您想调查实际发布之前最后运行的构建目标,诊断也可以。

Visual Studio 2013. Publish Web application to file system.

  <Target Name="Moose" AfterTargets="GatherAllFilesToPublish" >
    <Message Importance="high" Text="***Moooooooooooooooose***$(WPPAllFilesInSingleFolder)***$(TargetDir)" />
  </Target>

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.

花期渐远 2024-09-23 04:55:49

这似乎适用于 Visual Studio 2019

<Target Name="MyCustomTarget" AfterTargets="Publish">
  <Copy SourceFiles="C:\A.txt" DestinationFiles="C:\B.txt" />
</Target>

This seems to work in Visual Studio 2019

<Target Name="MyCustomTarget" AfterTargets="Publish">
  <Copy SourceFiles="C:\A.txt" DestinationFiles="C:\B.txt" />
</Target>
伤痕我心 2024-09-23 04:55:49
  • 您必须在文件末尾定义覆盖目标,在
  • 启动 MSBuild 并详细了解您的目标被忽略的原因:

    msbuild project.csproj /t:Target_to_Launch /v:d
    

AfterPublishPublish 目标之后调用,但 Publish > 不是您发布 Web 应用程序时调用的目标。 Publish 是发布ClickOnce 应用程序的目标。

您必须找到在 Visual Studio 中调用 Publish 时使用的目标,它可能是 PackageWebPublish...

  • You must define override the target at the end of your file, after <Import ... />
  • Launch MSBuild with detailed verbosity to see why your target is ignored :

    msbuild project.csproj /t:Target_to_Launch /v:d
    

AfterPublish is called after Publish target, but Publish 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 be Package, WebPublish...

俏︾媚 2024-09-23 04:55:49

我现在有点懒惰去找出混乱的目标,以找到适合基于文件的发布(您可能对此感兴趣)的目标。同时您可以做的是在 *.pubxml 文件中定义 AfterBuild 目标。

<Target Name="AfterBuild">

...

我建议还关闭属性“DeleteExistingFiles”,因为如果您将文件复制到正在发布的目录中,它会在发布过程中的某个地方进行清理。

<DeleteExistingFiles>False</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.

<Target Name="AfterBuild">

...

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.

<DeleteExistingFiles>False</DeleteExistingFiles>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文