title: Customize Publish for ASP.NET
body: <p>I have an asp.net project and need to run some code after each publish.</p>
  
  <p>I tried to acomplish this using to ways:</p>
  
  <ol>
  <li>Useing the vs project file</li>
  <li><p>Useing external build tool Cake (c# make)</p>
  
  <p>1.) So found some topics related to this issue:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/13781799/after-publish-event-in-visual-studio">After Publish event in Visual Studio</a></li>
  <li><a href="https://stackoverflow.com/questions/12899650/why-does-msbuild-ignore-my-beforepublish-target/12916009#12916009">Why does MSBuild ignore my BeforePublish target?</a></li>
  <li><a href="https://stackoverflow.com/questions/45582953/running-target-after-files-are-published-to-filesystem">Running Target after files are published to FileSystem</a></li>
  </ul></li>
  </ol>
  
  <p>So like suggested i added following code to my project file:</p>
  
  <pre><code>  &lt;Target Name="BeforePublish"&gt;
      &lt;Message Text="BeforePublish"&gt;&lt;/Message&gt;
      &lt;Warning Text="BeforePublish"&gt;&lt;/Warning&gt;
    &lt;/Target&gt;
    &lt;Target Name="AfterPublish"&gt;
      &lt;Message Text="AfterPublish"&gt;&lt;/Message&gt;
      &lt;Warning Text="AfterPublish"&gt;&lt;/Warning&gt;
    &lt;/Target&gt;
    &lt;Target Name="MSDeployPublish" &gt;
      &lt;Message Text="MSDeployPublish"/&gt;
      &lt;Warning Text="MSDeployPublish"/&gt;
    &lt;/Target&gt;
    &lt;Target Name="PipelinePreDeployCopyAllFilesToOneFolder" &gt;
      &lt;Message Text="PipelinePreDeployCopyAllFilesToOneFolder" /&gt;
      &lt;Warning Text="PipelinePreDeployCopyAllFilesToOneFolder" /&gt;
    &lt;/Target&gt;
    &lt;Target Name="BeforeBuild"&gt;
      &lt;Message Text="BeforeBuild"&gt;&lt;/Message&gt;
      &lt;Warning Text="BeforeBuild"&gt;&lt;/Warning&gt;
    &lt;/Target&gt;
    &lt;Target Name="AfterBuild"&gt;
      &lt;Message Text="AfterBuild"&gt;&lt;/Message&gt;
      &lt;Warning Text="AfterBuild"&gt;&lt;/Warning&gt;
    &lt;/Target&gt;
  </code></pre>
  
  <p>But only the Before- &amp; AfterBuild get executed. All the other targets just get ignored completly. Maybe it's because these other topics use VS 2010 and 2012. Is there a working way to do this in VS 2017?</p>
  
  <p>2.) When i use following code in a task I don't get same output as when i would have compiled it with VS.</p>
  
  <pre><code>   MSBuild(projectFile, new MSBuildSettings()
     .WithProperty("OutDir", publishDir)
     .WithProperty("DeployTarget", "WebPublish")
     .WithProperty("DeployOnBuild", "true")
     .WithProperty("WebPublishMethod", "FileSystem")
     .WithProperty("Configuration", "Release")
     );
  </code></pre>
  
  <p>Therefore this isn't a viable solution atm as well.</p>
  
  <p>I am thankful for any help getting this to work one way or another.</p>