Wednesday, July 30, 2008

AfterBuild copy task

Have you ever had to get a licence (.lic) file copied to your bin directory as part of you build?

Well annoyingly enough you don't want it to be marked as "Content" and you cant compile it, so I placed the following line into my .csproj file quite near the bottom. I have included the targets above so you can see where I placed it in bold.

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<CreateItem Include="$(ProjectDir)ThirdPartyLibraries\PowerUp.Web.UI.WebTree.lic">
<Output TaskParameter="Include" ItemName="LicenceFile" />
<Copy SourceFiles="@(LicenceFile)" DestinationFolder="$(OutputPath)" ContinueOnError="false" />

I created a target on the fly using the CreateItem step which also allows me to extend it later if I want to place more items inside it, then just referenced that item and copied it