Bin deploying linked files

Enable web publishing of linked files in _bin_deployableAssemblies

If like me you don't want to have duplicate copies of your bin dependencies between your libraries/packages folder and \_bin\_deployableAssemblies you'll want to link them; unfortunately the default Microsoft.WebApplication.targets won't publish them - absurd I know!

Through experimentation I've found the most elegant solution is to have have a custom targets files (checked into source control and branched from a common location) that I import into my web projects.

It simply overrides one of the targets in Microsoft.WebApplication.targets and copies linked files to a bin sub-folder before adding them to the CreateItem collection that is later used when building/publishing.

CopyLinkedBinDeployableAssemblies.targets

    <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name="_CopyBinDeployableAssemblies" Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
        <Copy Condition=" '%(Content.Link)' != '' " SourceFiles="%(Content.Identity)" DestinationFiles="$(MSBuildProjectDirectory)\bin\%(Content.Link)" />
        <CreateItem Include="$(MSBuildProjectDirectory)\bin\_bin_deployableAssemblies\**\*.*" Condition="Exists('$(MSBuildProjectDirectory)\bin\_bin_deployableAssemblies')">
          <Output ItemName="_binDeployableAssemblies" TaskParameter="Include" />
        </CreateItem>
        <CreateItem Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*" Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
          <Output ItemName="_binDeployableAssemblies" TaskParameter="Include" />
        </CreateItem>
        <Copy SourceFiles="@(_binDeployableAssemblies)" DestinationFolder="$(OutDir)\%(RecursiveDir)" SkipUnchangedFiles="true" Retries="$(CopyRetryCount)" RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
      </Target>
    </Project>

Then in my web .csproj project file add an import link to the new targets file;

    <Import Project="$(MSBuildProjectDirectory)\..\..\BuildSupport\Targets\CopyLinkedBinDeployableAssemblies.targets" />

Important! Make sure you put this after the Import to Microsoft.WebApplication.targets.

Finally...

There seems to be a myth that \_bin\_deployableAssemblies is MVC3 only which of course is utter tosh, this works for any project that uses Microsoft.WebApplication.targets; I know this as we use it in our FubuMVC projects to copy Simple.Data MEF dependencies :-)