Building solutions that reference to assemblies belonging to different team project
Scenario
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
$/TP1/Framework/Common/v2.0/commonlibrary.dll $/TP2/Main/ConsoleApplication1/ConsoleApplication1.sln $/TP2/Main/ConsoleApplication1/ConsoleApplication1.sln
$/TP1/Framework/Common/v2.0/commonlibrary.dll
$/TP2/Main/ConsoleApplication1/ConsoleApplication1.sln
Note: please make sure that you have used File Reference to add the reference for commonlibrary.dll and CopyLocal option is set to true. Otherwise your desktop build scenario will be broken.
Custom steps to enable building the project
<SkipInitializeWorkspace>true</SkipInitializeWorkspace>
<TfCommand>$(TeamBuildRefPath)\..\tf.exe</TfCommand>
<ItemGroup> <Map Include="$/TP2/Main"> <LocalPath>$(SolutionRoot)\Main</LocalPath> </Map> <Map Include="$/TP1/Framework"> <LocalPath>$(SolutionRoot)\Framework</LocalPath> </Map> </ItemGroup>
<ItemGroup>
<Map Include="$/TP2/Main">
<LocalPath>$(SolutionRoot)\Main</LocalPath>
</Map>
<Map Include="$/TP1/Framework">
<LocalPath>$(SolutionRoot)\Framework</LocalPath>
</ItemGroup>
<Target Name="BeforeGet">
<!— to remove any workspace that exist with the same name, from some previous build à <DeleteWorkspaceTask TeamFoundationServerUrl="$(TeamFoundationServerUrl)" Name="$(WorkspaceName)" /> <!— create the workspace with default mapping that maps $(SolutionRoot) to $/ à <Exec WorkingDirectory="$(SolutionRoot)" Command=""$(TfCommand)" workspace /new $(WorkspaceName) /server:$(TeamFoundationServerUrl)"/> <!— task will add the folder mappings corresponding to items define in step 5 à <Exec WorkingDirectory="$(SolutionRoot)" 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) à <Exec WorkingDirectory="$(SolutionRoot)" Command=""$(TfCommand)" workfold /unmap /workspace:$(WorkSpaceName) "$(SolutionRoot)""/>
<!— to remove any workspace that exist with the same name, from some previous build à
<DeleteWorkspaceTask
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
Name="$(WorkspaceName)" />
<!— create the workspace with default mapping that maps $(SolutionRoot) to $/ à
<Exec
WorkingDirectory="$(SolutionRoot)"
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)""/>
</Target>
<SolutionToBuild Include="$(SolutionRoot)\Main\ConsoleApplication1\ConsoleApplication1.sln" /> <SolutionToBuild Include="$(SolutionRoot)\Main\ConsoleApplication2\ConsoleApplication2.sln" />
<SolutionToBuild Include="$(SolutionRoot)\Main\ConsoleApplication1\ConsoleApplication1.sln" />
<SolutionToBuild Include="$(SolutionRoot)\Main\ConsoleApplication2\ConsoleApplication2.sln" />
Recommendations
<Exec Command=""$(TfCommand)" workfold /unmap /workspace:$(WorkSpaceName) "$(SolutionRoot)"" WorkingDirectory="$(SolutionRoot)"/>
References
Other interesting posts on the related/same issue are [post] [post1] [post2] [post3]