Web Deployment projects in a Team Build.
Recently one of our customers decided to incorporate Team System into there development process. They wanted to migrate al there existing sources from there source repository system to Team Foundation Version Control.
The sources mainly exist of ‘old’ asp code and some vb 6.0 code. There is some .NET 1.1 code as well but it will be migrated to .NET 2.0.
I have been asked to help implement a Team Foundation Build to compile the .NET code and deploy the deliverables as well as the asp files.
As described in this post, Team Build calls various targets. Some of those targets are already implemented by Microsoft. One of the default implemented targets is the CoreDropBuild target. This target is responsible for copying the output files to a deployment directory.
The files being copied are the assemblies that are created in the build, the program database files and files that are marked in the projects as files to be copied to the output directory (property: Copy To Output Directory is set to true.)
Al these files, for all the solutions in the build, are copied to a single directory. Unfortunately, this results in some unwanted behavior. Because all the files are copied to a single directory, files with the same filename are overwritten and only one copy of a file with a specific filename is available in this directory.
Furthermore, because all the files are dropped into a single directory, directory structures needed for the application (especially websites) are no longer available.
Fortunately Microsoft recently released a new project type, the Web Deployment project type that helped us a lot.
This project is linked to a Web site project or a Web application project and ensures that the websites are correctly deployed using MsBuild.
A small problem occurs however when those web deployment projects are used in a Team Build environment. Because the default Team Build implementation builds the output of all the projects in a build to a single build directory, the bin directory for each project is empty. The Web Deployment project however expects that the binaries for the web site/application projects are located in those bin directories.
As the Visual Studio 2005 project files are actually MsBuild files, this problem is easily fixed. Just add some custom MsBuild code to the web site/application project files to copy the output files back.
Here is an example of the MsBuild code I used, to copy the binaries back to the project bin folder.
<Target Name=“AfterBuild“>
<CreateItem Include=“$(OutDir)$(AssemblyName).*“>
<Output ItemName=“FilesToCopy“ TaskParameter=“Include“ />
< SPAN>CreateItem>
<Copy SourceFiles=“@(FilesToCopy)“
DestinationFiles=“@(FilesToCopy –> ‘$(MSBuildProjectDirectory)Bin%(Filename)%(Extension)’)“
ContinueOnError=“true“
/>
<ResolveAssemblyReference Assemblies=”$(AssemblyName)” SearchPaths=”$(OutDir);{TargetFrameworkDirectory};{GAC}” TargetFrameworkDirectories=”$(TargetFrameworkDirectory)” FindDependencies=”true” FindSatellites=”true” FindSerializationAssemblies=”true” FindRelatedFiles=”true”> <Output TaskParameter=”CopyLocalFiles” ItemName=”RefToCopy” /> < SPAN>ResolveAssemblyReference> <Copy SourceFiles=“@(RefToCopy)“ DestinationFiles=“@(RefToCopy -> ‘$(MSBuildProjectDirectory)Bin%(Filename)%(Extension)’)“ ContinueOnError=“true“ /> < SPAN>Target>
The AfterBuild target is used to copy the project output (binaries) and the appropriate referenced assemblies back to the bin folder. This target is one of the targets that are provided by Microsoft to add customizations.
Hopes this helps,