Bin deploying linked files
Enable web publishing of linked files in _bin_deployableAssemblies
Friday 16 December 2011 at 09:18 am.
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 ![]()
No comments
Wow! Can I work for you?! ** Breath of fresh air in management! **
Ian:There will have to be very strict guidelines, the last thing you want is dispute over “.. but you gave him 5 credits and her only 3?!” which will undoubtedly lead to the scheme being rescinded. That re…
Gary Ewan Park:This is a very interesting idea! It does leave some questions about how it is “policed”, and who decides whether a particular blog post, or SO answer warrants the credits, but I really do think that i…
Chris Marisic:Being both a developer and a leader of developers, I have found little to be as integral to the speed and success of software development as intellisense. This is also why I leverage R# on top of Vis…
Franc:I have to admit that Spark won me over very quickly, yes it is not perfect and yes I am not an expert in the subject but it has provided me with new skills. I have been a victim of its lack of intellis…
Randolph Burt:Intellisense helps me code faster and make less mistakes. However, from a personal point of view, it can be the difference between enjoying development and not enjoying development – and if you don’t …