Include extra files in WebDeploy Package

There are many examples on the web which provide example MSBuild script to add extra files (not referenced by the project) into a WebDeploy package.  Chief among them is Sayed Hashimi’s blog post detailing how it all works.  By injecting into the WebDeploy packaging targets you can add additional files into the files to be packaged.

<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include="..\Extra Files\**\*" />
    <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
      <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

These all appear to be older posts however.  I have no doubt this worked when Sayed and others blogged it, but this doesn’t appear to work with the latest VS bits.

The Solution

The parent target which eventually triggers the CopyAllFilesToSingleFolderForPackageDependsOn target does not appear to be used any longer.  I found where it was referenced back in the VS2010 release of these target but it doesn’t look like its been used since then.  The new (very similar) target that appears to have replaced it is the CopyAllFilesToSingleFolderForMSDeployDependsOn target. Simply changing “Package” to “MSDeploy” should fix this issue.

<PropertyGroup>
  <CopyAllFilesToSingleFolderForMSDeployDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForMSDeployDependsOn);
  </CopyAllFilesToSingleFolderForMSDeployDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include="..\Extra Files\**\*" />
    <FilesForPackagingFromProject  Include="%(_CustomFiles.Identity)">
      <DestinationRelativePath>Extra Files\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

Obviously, the same change applies to removing files from a package.

If this solves your issue or you have further questions, please comment below or continue the conversation on Twitter/Reddit.

6 thoughts on “Include extra files in WebDeploy Package”

  1. Thanks for posting this – very subtle and trivial, but caused something to break which would have been rather hard to have diagnosed without this pointer. I knew the issue would reside in the csproj – but where!

  2. Was looking for a way to copy files from another location into the publish package and found this. This was awesome, used in VS2013 and works great.

Leave a Reply