How do I build a Team Project with shared code?

One question that comes up a lot in Team System deployments is "how do I share code across team projects"? The easiest way to accomplish this is to set up a Team Project specifically for common, shared code. Here's a simple example of this scenario.

We have one Team Project for ClientApp, and a second Team Project for CommonUtils. ClientApp is a console application that references CommonUtils.

These projects will share a common path on the hard drive:

  • c:\tfsprojects\ClientApp
  • c:\tfsprojects\CommonUtils

And they'll have workspace mappings to those local hard drive paths:

Source Control FolderLocal Folder
$/ClientAppc:\tfsprojects\ClientApp
$/CommonUtilsc:\tfsprojects\CommonUtils

CommonUtils is a Class Library project with a post-build event to copy its output to a \binaries folder:

The resulting path is c:\tfsprojects\CommonUtils\CommonUtils\binaries\CommonUtils.dll. The ClientApp project will reference this DLL:

We can now create a Team Build for ClientApp.

However, this build will fail! Team Build cannot figure out the shared DLL reference and thus throws an error. The build output log shows the exact error:

warning MSB3245: Could not resolve this reference. Could not locate the assembly "CommonUtils". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors

However, we can fix this. Thanks to a helpful post by Manish Agarwal, we know how to edit the TFSBuild.proj script to fix this. Check out the clientappbuild build script from Source Control Explorer, and begin editing.

1) add these variables to the PropertyGroup section:

<!-- to be added under PropertyGroup -->
<
TfCommand>$(TeamBuildRefPath)\..\tf.exe</TfCommand>
<
SkipInitializeWorkspace>true</SkipInitializeWorkspace>

2) add these ItemGroup entries which map both Team Projects and both solutions:

<ItemGroup>
  <!--
add one entry for every solution we reference -->
  <
SolutionToBuild Include="$(SolutionRoot)\CommonUtils\CommonUtils.sln" />
  <
SolutionToBuild Include="$(SolutionRoot)\ClientApp\ClientApp.sln" />
</
ItemGroup>

<ItemGroup>
  <!--
add one entry for every Team Project we reference -->
  <
Map Include="$/ClientApp/ClientApp">
    <
LocalPath>$(SolutionRoot)\ClientApp</LocalPath>
  </
Map>
  <
Map Include="$/CommonUtils/CommonUtils">
    <
LocalPath>$(SolutionRoot)\CommonUtils</LocalPath>
  </
Map>
</
ItemGroup>

3) hook up the BeforeGet event to retrieve the workspaces for each Team Project, too:

<Target Name="BeforeGet">
  <
DeleteWorkspaceTask
      
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
      
Name="$(WorkspaceName)" />
  <
Exec
    
WorkingDirectory="$(SolutionRoot)"
    
Command="&quot;$(TfCommand)&quot; workspace /new $(WorkSpaceName) /server:$(TeamFoundationServerUrl)"/>
  <
Exec
  
WorkingDirectory="$(SolutionRoot)"
   Command="&quot;$(TfCommand)&quot; workfold /unmap /workspace:$(WorkSpaceName) &quot;$(SolutionRoot)&quot;"/>
  <
Exec
    
WorkingDirectory="$(SolutionRoot)"
    
Command="&quot;$(TfCommand)&quot; workfold /map /workspace:$(WorkSpaceName) /server:$(TeamFoundationServerUrl) &quot;%(Map.Identity)&quot; &quot;%(Map.LocalPath)&quot;"/>
</
Target>

Check in the build script, execute it, and now we have a successful Team Build of a Team Project that references a DLL in another Team Project:

And our build output folder contains what we would expect-- the application DLL, and the shared dependency DLL, too:

(Thanks to Eric Cherng for his help in writing this blog post!)

posted on Tuesday, August 22, 2006 11:15 AM by jatwood

Comments

# re: How do I build a Team Project with shared code?

There's also the AdditionalReferencePath variable, which can be added to your TFSBuild.proj script. It adds some new hinting paths specifically for resolving references during the build process:

<AdditionalReferencePath Include="$(SolutionRoot)\Binaries">

This is from Manish's blog:

http://blogs.msdn.com/manishagarwal/archive/2005/09/28/474769.aspx
Tuesday, August 22, 2006 2:19 PM by Jeff Atwood

# Two good posts: Building projects with shared code and using Web Application Projects (WAP)

Last week, the folks at Vertigo Software wrote a couple of really good posts involving Team Build.
The...
Tuesday, August 29, 2006 5:09 AM by Buck Hodges

# ASP.NET 結合 Team Build. 相當重要的議題

我一直認為, 好的軟體架構師 絕對不是 天上飛的那種
否則就是定義上的 模糊... 至少 和我的不一樣...
對於 軟體佈署議題 我一項認為 是非常重要的...
這裡收集的兩分 文件 剛好 點綴出...
Saturday, September 02, 2006 8:56 AM by Refines.Info["Polo Lee"]

# ASP.NET 結合 Team Build. 相當重要的議題

我一直認為, 好的軟體架構師 絕對不是 天上飛的那種
否則就是定義上的 模糊... 至少 和我的不一樣...
對於 軟體佈署議題 我一項認為 是非常重要的...
這裡收集的兩分 文件 剛好 點綴出...
Saturday, September 02, 2006 8:59 AM by Refines.Info["Polo Lee"]

# Migrando de Visual Source Safe a Team Foundation Server

Buenas, desde hace unos d&#237;as estamos manteniendo una conversaci&#243;n interesante dentro de los foros de
Saturday, September 02, 2006 9:03 AM by El Bruno

# ASP.NET 結合 Team Build. 相當重要的議題

我一直認為, 好的軟體架構師 絕對不是 天上飛的那種
否則就是定義上的 模糊... 至少 和我的不一樣...
對於 軟體佈署議題 我一項認為 是非常重要的...
這裡收集的兩分 文件 剛好 點綴出...
Saturday, September 02, 2006 8:20 PM by Refines.Info["Polo Lee"]

# re: How do I build a Team Project with shared code?

Despite the historical odds, this might be a dumb question, but I'm working with TFS and trying to set up a series of dependent projects (e.g. Enterprise Library -> NUnit). I'm wrestling with how to approach version control. In workspaces that modify NUnit, Enterprise Library wouldn't be accessed at all. In workspaces that modify Enterprise Library, NUnit would be accessed but not modified. In these workspaces (those that modify Enterprise Library), how can TFS help me communicate to developers that they should not get the latest from the NUnit project, but that they should get a labelled version.

Is the best answer here to use a branching strategy that promotes a development project to a release project and then maintains a dependency to the release project? Right now I'm favoring this approach based on all factors except the overhead involved. Experience appreciated.
Thursday, September 07, 2006 7:48 AM by dls

# re: How do I build a Team Project with shared code?

Thank you for the very clearly written post. This works great for the Team Build. However, what about developer workstation builds in Visual Studio? Team members working on the ClientApp.sln have to open the CommonUtils.sln, Get Latest, and Rebuild every time they want to get updated Common Util code.

It would be great if the resulting binaries could be source controlled in such a way that if you got latest in the ClientApp.sln, you would get the latest CommonUtils dlls.
---
Also, when using this described approach, does Team Build label the shared CommonUtils code with the build label? If not, how could you repeat a previous build.
Thursday, September 07, 2006 8:52 PM by John R.

# 另一種不同運用 Build 技巧於 Team Project

雖然是 8/23 但因為這篇 Post 裡頭的概念實在太好了,所以我還是需要把他由我過去的 筆記本中 挖到這個開放 Blog 裡頭 哪裡好呢 ? 主要在 過去 Team System 推導上 我相信很多人都會...
Saturday, September 16, 2006 6:45 AM by Refines.Info["Polo Lee"]

# re: How do I build a Team Project with shared code?

> Is the best answer here to use a branching strategy that promotes a development project to a release project and then maintains a dependency to the release project?

I think this is the simplest and most effective way.. consider the alternatives:

1) Get and build the latest version of the dependency every time you build your project. That's what is shown in this article, but it may not be appropriate for every project.

2) Check the dependency binaries into source control and reference the binaries from your project.

3) Branch the dependency and reference the project from your project.
Tuesday, September 19, 2006 12:45 PM by Jeff Atwood

# Migrando de Visual Source Safe a Team Foundation Server

Buenas, desde hace unos d&amp;iacute;as estamos manteniendo una conversaci&amp;oacute;n interesante dentro de
Saturday, September 30, 2006 5:19 AM by El Bruno

# Team Foundation Server - Sharing Binaries and Class Libraries Across Multiple Projects

I returned to work after Tuesday's MSDN Roadshow fired up and full of ideas, eager to try out ASP.NET
Saturday, March 17, 2007 3:53 PM by Ian Nelson

# Team Foundation Server - Sharing Binaries and Class Libraries Across Multiple Projects

I returned to work after Tuesday's MSDN Roadshow fired up and full of ideas, eager to try out ASP.NET
Saturday, March 17, 2007 3:55 PM by Ian Nelson

#

Huaahhh… ini kasus yang umum namun anehnya agak perlu sedikit effort untuk bisa berhasil. Kasus apa sih
Tuesday, February 03, 2009 4:49 AM by Futorial

# Adderall.

Buy adderall. Adderall xr. Adderall abuse. Adderall.
Friday, May 29, 2009 9:38 PM by Adderall.

# Adderall.

Adderall xr headache. Mexican pharmacies adderall. Adderall.
Saturday, May 30, 2009 8:12 PM by Adderall xr snort.

# Vicodin.

No prescription vicodin. Vicodin detox. Mexican vicodin.
Sunday, May 31, 2009 6:57 PM by Symptoms vicodin addiction.