I use the _bin_deployableAssemblies folder to copy through ASP.NET MVC assemblies to the bin folder after each build. Unfortunately, the MSBuild task also copies the hidden .svn folder.
First attempt to fix
I want to solve this problem at the project level, so I added the RemoveDir task to the RemoveDir target in the AfterBuild file, which works for regular builds.
<RemoveDir Directories="@(OutDir).svn" />
But it does not work when I publish the site. After publishing, the .svn folder will be copied to the destination folder of the publishing wizard. And, oddly enough, it also ends up in the / bin folder in the project, despite the RemoveDir task!
In the target file C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets dynamic group of elements is created to include all the files in the _bin_deployableAssemblies folder:
<CreateItem Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*" Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')"> <Output ItemName="_binDeployableAssemblies" TaskParameter="Include"/> </CreateItem>
Using the Message task in AfterBuild target, I see that this group of items included all the files in the .svn folder.
Second attempt to fix
So, I tried the following trick to set up a group of elements in target.AfterBuild:
<ItemGroup> <_binDeployableAssemblies Remove="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\.svn\**\*.*" /> </ItemGroup>
If I print the list of files after that using the Message task, I see that it no longer contains the files in the .svn folder. But , .svn files are still copied to the output folder when you create or publish!
Possible actual fix
It seems that the Publish command first performs a regular build, after which we can delete the files using the AfterBuild target. But then he is going to copy the files to a temporary location (in the / obj folder) to publish them. At this point, it seems that it copies everything from _bin_deployableAssemblies to bin again and only then copies bin (and other project files) to a temporary location. It seems to have happened after AfterBuild.
Thus, the trick may be to connect to the process somewhere before the project files are copied to a temporary folder. Or after that, but the second time you need to clear not only the temporary folder, but also the original bin folder. This may be possible by connecting to one of the many DependsOn targets.
If there is no suitable purpose for this, perhaps deleting files from a certain group of intermediary elements may be a solution, so they will never be copied or published.
I could not achieve any of these possible corrections due to a lack of understanding of the publishing process.
Main question
How can I either prevent file copying or delete files after copying them? How to do this for both regular assemblies and the publish team?