title: Running Target after files are published to FileSystem
body: <p>I am trying to create publish profile which would copy all published files to various folders. Unfortunately I read that's not possible to do it directly through <code>publishUrl</code> and it's advised to publish to one folder from which to copy all the files. I managed to write the copy target functionality, but the order of when targets are run is wrong.
  I'm trying to run the publish directly from VisualStudio 2015, through Build > Publish Web.</p>
  
  <p>Here is my publish profile:</p>
  
  <pre><code>&lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;PropertyGroup&gt;
      &lt;WebPublishMethod&gt;FileSystem&lt;/WebPublishMethod&gt;
      &lt;LastUsedBuildConfiguration&gt;Debug&lt;/LastUsedBuildConfiguration&gt;
      &lt;LastUsedPlatform&gt;Any CPU&lt;/LastUsedPlatform&gt;
      &lt;SiteUrlToLaunchAfterPublish /&gt;
      &lt;LaunchSiteAfterPublish&gt;False&lt;/LaunchSiteAfterPublish&gt;
      &lt;ExcludeApp_Data&gt;True&lt;/ExcludeApp_Data&gt;
      &lt;publishUrl&gt;obj\Package\PackageTemp&lt;/publishUrl&gt;
      &lt;DeleteExistingFiles&gt;True&lt;/DeleteExistingFiles&gt;
      &lt;ExcludeFilesFromDeployment&gt;Web.config;package.json;packages.config;Typescript\**;DynamicCss\**;gulpfile.js;&lt;/ExcludeFilesFromDeployment&gt;
    &lt;/PropertyGroup&gt;
    &lt;Import Project="AdditionalResources.targets" /&gt;
    &lt;PropertyGroup&gt;
      &lt;CopyAllFilesToSingleFolderForPackageDependsOn&gt;AdditionalResources&lt;/CopyAllFilesToSingleFolderForPackageDependsOn&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;DestLocations Include="D:\PUBLISH_TEST\" /&gt;
      &lt;DestLocations Include="D:\PUBLISH_TEST2\" /&gt;
    &lt;/ItemGroup&gt;
    &lt;Target Name="CopyToDeployFolders" AfterTargets="CopyAllFilesToSingleFolderForPackage" Outputs="%(DestLocations.Identity)"&gt;
      &lt;ItemGroup&gt;
        &lt;PublishedFiles Include="obj\Package\PackageTemp\**\*" /&gt;
      &lt;/ItemGroup&gt;
      &lt;Message Importance="high" Text="FilesToCopy: @(PublishedFiles)" /&gt;
      &lt;PropertyGroup&gt;
        &lt;_DeployPathIdentity&gt;%(DestLocations.Identity)&lt;/_DeployPathIdentity&gt;
      &lt;/PropertyGroup&gt;
      &lt;Copy SourceFiles="@(PublishedFiles)" DestinationFiles="@(PublishedFiles-&gt;'$(_DeployPathIdentity)%(RecursiveDir)%(Filename)%(Extension)')" /&gt;
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>The order in which it's run is as follows:</p>
  
  <pre><code>Build
  AdditionalResources
  CopyToDeployFolders
  Publish folder
  </code></pre>
  
  <p>Which is problematic, because my temp folder is not yet created/published. I tried to make my CopyToDeployFolders Target to override AfterPublish and tried to use various different AfterTargets, but none of them worked - sometimes my target was not executed or is run still before publish folder.</p>
  
  <p>I tried to found out which target is run by looking at 
  c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets
  as indicated by this answer <a href="https://stackoverflow.com/questions/12899650/why-does-msbuild-ignore-my-beforepublish-target/12916009#12916009">Why does MSBuild ignore my BeforePublish target?</a>, but didn't find the correct one, tried to changed AfterTarget to different ones, but the results are still the same.</p>
  
  <p>Edit:
  Output with Diagnostic level:</p>
  
  <pre><code>2&gt;    Target "GatherAllFilesToPublish" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets" from project "C:\MyProject\MySite\MySite.csproj" (entry point):
  2&gt;        Done building target "GatherAllFilesToPublish" in project "MySite.csproj".
  2&gt;Done building project "MySite.csproj".
  2&gt;Deleting existing files...
  2&gt;Publishing folder /...
  ... files being published ...
  2&gt;Web App was published successfully file:///C:/MyProject/MySite/MySite/obj/Package/PackageTemp
  2&gt;
  </code></pre>
  
  <p>Edit2:
  Added content of AdditionalResources.targets</p>
  
  <pre><code>&lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;Target Name="AdditionalResources"&gt;
      &lt;ItemGroup&gt;
        &lt;AddFiles Include="$(ProjectDir)\App_Themes\**\Basic\Dynamic.css"&gt;
          &lt;CustomPath&gt;App_themes\&lt;/CustomPath&gt;
        &lt;/AddFiles&gt;
        &lt;AddFiles Include="C:\y\SharedDLL\Clients\Web\bin\**\*.dll"&gt;
          &lt;CustomPath&gt;bin\&lt;/CustomPath&gt;
        &lt;/AddFiles&gt;
        &lt;AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\**\ctrl_res\**\*.*" /&gt;
        &lt;AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\js\**\*.*"&gt;
          &lt;CustomPath&gt;js\&lt;/CustomPath&gt;
        &lt;/AddFiles&gt;
        &lt;AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\**\ClientBin\**\*.xap" /&gt;
        &lt;AddFiles Include="C:\y\SharedDLL\Clients\Web\resources\FileUpload\**\*.js"&gt;
          &lt;CustomPath&gt;js\&lt;/CustomPath&gt;
        &lt;/AddFiles&gt;
        &lt;!-- Minified files should be copied last to override non-minified ones --&gt;
        &lt;AddFiles Include="$(ProjectDir)\MINIFIED_FILES\**\*.*" /&gt;
      &lt;/ItemGroup&gt;
      &lt;ItemGroup&gt;
        &lt;FilesForPackagingFromProject Include="%(AddFiles.Identity)"&gt;
          &lt;DestinationRelativePath&gt;%(AddFiles.CustomPath)%(RecursiveDir)%(Filename)%(Extension)&lt;/DestinationRelativePath&gt;
        &lt;/FilesForPackagingFromProject&gt;
      &lt;/ItemGroup&gt;
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>