title: MSBuild: Add and remove files to a msbuild 15 publish output @ BeforeTargets="PrepareForPublish"
body: <p>I want to add and delete files when I publish in msbuild 15.</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk.Web"&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp2.0&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;Folder Include="wwwroot\" /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /&gt;
    &lt;/ItemGroup&gt;
  
    &lt;!-- My target, which is only executed on publication , Which is desirable in my case --&gt;
    &lt;Target Name="MyPrepareForPublish" BeforeTargets="PrepareForPublish"&gt;
  
      &lt;!-- Delete old files in wwwroot from Content --&gt;
      &lt;ItemGroup&gt;
          &lt;Content Remove="wwwroot\**"/&gt;
      &lt;/ItemGroup&gt;
  
      &lt;!-- I Add and removes files to file system in wwwroot here , Exclude="@(Content)" prevents duplicates from outside wwwroot --&gt;
  
      &lt;!-- Adding new files to Content form wwwroot --&gt;
      &lt;ItemGroup&gt;
          &lt;Content Include="wwwroot\**" Exclude="@(Content)"/&gt;
      &lt;/ItemGroup&gt;
  
   &lt;/Target&gt;
  
  &lt;/Project&gt;
  </code></pre>
  
  <p>But when I remove and add files, I get an error  message :</p>
  
  <pre><code>(109,5): Error MSB3030: Could not copy the file "C:\buildTest\WebsSrver\wwwroot\main.d158e9e1259986c4bd76.bundle.js" because it was not found.
  </code></pre>
  
  <p>My code deletes "main.d158e9e1259986c4bd76.bundle.js" and creates a new one with another name in MyPrepareForPublish.</p>
  
  <p>The files are located in wwwroot im my dotnet core project.</p>
  
  <p>So how do I specify what should be included in publish output ?</p>
  
  <p>Thanks in advance !</p>