AfterPublish target not working

后端 未结 5 1019
抹茶落季
抹茶落季 2020-12-01 10:40

World\'s simplest task (see below) is not being executed after I publish my web application project. Any idea why?


  <         


        
相关标签:
5条回答
  • 2020-12-01 10:51

    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.

    0 讨论(0)
  • 2020-12-01 10:54
    • 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...

    0 讨论(0)
  • 2020-12-01 10:54

    This seems to work in Visual Studio 2019

    <Target Name="MyCustomTarget" AfterTargets="Publish">
      <Copy SourceFiles="C:\A.txt" DestinationFiles="C:\B.txt" />
    </Target>
    
    0 讨论(0)
  • 2020-12-01 10:58

    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. "&gt" 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.
    0 讨论(0)
  • 2020-12-01 11:17

    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>
    
    0 讨论(0)
提交回复
热议问题