Building solutions that reference to assemblies belonging to different team project
Assume that we two projects (ConsoleApplication1 and ConsoleApplication2) under team project (TP1) and they are using the assembly (commonlibrary.dll) that is checked in under a different team project (TP2). Let us assume the corresponding paths under version control are
Custom steps to enable building the project
Create the BuiltType “Type1” for TP2.
Check out the Tfsbuild.proj file for “Type1” build type.
Reset the following property. This is done to skip invoking the default tasks to delete and recreate workspace on the build machine.
Define the new property. This is just for the user convenience and will be used in the custom target “BeforeGet” (mentioned below)
Define the folder mappings item group. (You are responsible for giving the correct local paths for the build machine. Please note that multiple mappings can not share the same local folder and will result in MappingConflictException in the CreateWorkspace task. Another recommendation is to avoid mapping to $(SolutionRoot). This is because if while creating workspace, task detects overlapping local paths, it will try to merge the local paths and screw up the relative paths. Please note that I have not explored the cloaking option.
<ItemGroup> <Map Include=“$/TP2/Main“> <LocalPath>$(SolutionRoot)\Main</LocalPath> </Map> <Map Include=“$/TP1/Framework“> <LocalPath>$(SolutionRoot)\Framework</LocalPath> </Map> </ItemGroup>
Override the “BeforeGet” target.
<!— to remove any workspace that exist with the same name, from some previous build à
<!— create the workspace with default mapping that maps $(SolutionRoot) to $/ à
Command=“"$(TfCommand)" workspace /new $(WorkspaceName) /server:$(TeamFoundationServerUrl)“/>
<!— task will add the folder mappings corresponding to items define in step 5 à
Command=“"$(TfCommand)" workfold /map /workspace:$(WorkSpaceName) /server:$(TeamFoundationServerUrl) "%(Map.Identity)" "%(Map.LocalPath)"“/>
<!— remove the default mapping ( $(SolutionRoot) ß> $/)that was created initially. Otherwise all the team projects will be synced under the $(SolutionRoot) à
Command=“"$(TfCommand)" workfold /unmap /workspace:$(WorkSpaceName) "$(SolutionRoot)"“/>
Verify that sln paths (SolutionToBuild itemgroup) for correct relative paths
<SolutionToBuild Include=“$(SolutionRoot)\Main\ConsoleApplication1\ConsoleApplication1.sln“ />
<SolutionToBuild Include=“$(SolutionRoot)\Main\ConsoleApplication2\ConsoleApplication2.sln“ />
Similarly verify the vsmdi paths (MetaDataFile itemgroup) for correct relative paths.
Checkin the tfsbuild.proj file and launch the build.
Please make sure that CopyLocal option is set for the file reference.
Use File reference to add references for assemblies belonging to different team projects. Sometime these reference paths will be broken because the relative path on the build machine is different from the one mentioned in the csproj file of your project. In such cases you need to specify the correct location of the external assembly. You can easily do it by defining “AdditionalReferencePath” item pointing to the folder containing the assembly.
Please try to avoid mapping directly to “$(SolutionRoot)”. Still if your “Map” item group contains any working folder mapping that points to only “$(SolutionRoot)”, then you need to remove the following line from the BeforeGet target :-
<Exec Command=“"$(TfCommand)" workfold /unmap /workspace:$(WorkSpaceName) "$(SolutionRoot)"“ WorkingDirectory=“$(SolutionRoot)“/>