4

I am using the _bin_deployableAssemblies folder to copy over the 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 at a project level, so I have added a RemoveDir task to the AfterBuild target in the .csproj file, which works for normal builds.

<RemoveDir Directories="@(OutDir).svn" />

But it doesn't seem to work when I publish the site. After publishing the .svn folder is copied to the destination folder of the publish wizard. And strangely it also ends up in the /bin folder in the project, despite the RemoveDir task!

In the targets file C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets an item group is created dynamically to include all files in the folder _bin_deployableAssemblies:

<CreateItem Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*" 
            Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
    <Output ItemName="_binDeployableAssemblies" TaskParameter="Include"/>
</CreateItem>

Using a Message task in the AfterBuild target I can see that this item group included all files in the .svn folder.

Second attempt to fix

So I tried the following trick to adjust the item group in the .AfterBuild target:

<ItemGroup>
    <_binDeployableAssemblies Remove="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\.svn\**\*.*" />
</ItemGroup>

If I print the list of files after that using a Message task I can see that it no longer includes the files in the .svn folder. But, the .svn files are still copied to the output folder when building or publishing!

Possible actual fix

It seems that the Publish command first does a regular build, at which point we can remove the files using the AfterBuild target. But then it is going to copy files to a temporary location (in the /obj folder) in order to publish them. During this phase it seems that it copies everything from _bin_deployableAssemblies over to bin again and only then copies bin (and other project files) to the temporary location. This seems to happen after AfterBuild.

So the trick might be to hook into the process somewhere before the project files are copied to the temporary folder. Or afterwards, but then not only the temporary folder needs to be cleaned, but also the original bin folder, for the second time. This may be possible by hooking into one of the many DependsOn targets.

If there is no suitable target to do this, then perhaps removing the files from some intermediary item group could be a solution so they never actually get copied or published.

I have not been able to achieve either of these possible fixes due to a lack of understanding of the Publish process.

Main question

How can I either prevent the files from being copied or remove the files after they are copied? How can I do this for both regular builds and the publish command?

Michiel van Oosterhout
  • 22,839
  • 15
  • 90
  • 132

1 Answers1

5

Add this to your .csproj file (or the {projectName}.wpp.targets file):

  <PropertyGroup>
    <OnAfterCopyAllFilesToSingleFolderForPackage>
      __RemoveSvnFromPackageTemp
    </OnAfterCopyAllFilesToSingleFolderForPackage>
  </PropertyGroup>

  <Target Name="__RemoveSvnFromBin" AfterTargets="_CopyBinDeployableAssemblies">
    <Message Text="Removing .SVN from BIN" Importance="normal"/>
    <RemoveDir Directories="$(OutDir).svn" />
  </Target>

  <Target Name="__RemoveSvnFromPackageTemp">
    <Message Text="Removing .SVN from PackageTempDir" Importance="normal"/>
    <RemoveDir Directories="$(_PackageTempDir)\bin\.svn" />
  </Target>

That works for Build, Package, and Publish!

mthierba
  • 5,587
  • 1
  • 27
  • 29