views:

1114

answers:

4

We have a TFS 2008 project with two branches ("Main" and "NewFeature"). Each is a complete, independent "copy" (variant) of the source code.

By changing the workspace mappings, we can map either variant onto our local PCs and have been working with both branches with no problems.

However, if I set up the mappings to switch our build server on to the NewFeature branch (which should simply swap in the NewFeature source code without changing anything else as far as the build server is concerned) I get errors:

There is no working folder mapping for $/Main/Product.sln

i.e. when it is building from the NewFeature branch, something is still looking in the Main branch, even though there are no references anywhere in the source code to this branch. It appears to be caching some reference to Main?!

I have done a completely clean build (deleted the build folder from the server and run the build with /p:ForceGet=true to make sure the mapping is flushed through to the server, and there are no files on the server that might cache the workspace bindings), but this doesn't help.

Any suggestions?

+1  A: 

Verify that:

  • $(SolutionToBuild) uses a relative path when referencing Product.sln
  • the relative path between $/NewFeature/.../TFSBuild.proj and $/NewFeature/Product.sln is the same as it is in the Main branch.

/ EDIT /

Note, however, it's not important that $/Main and $/Branches/Feature live at the same level in the tree hierarchy. Nor should the local path on the build server matter.* All that matters is what's underneath each branch. If the contents is internally consistent then all of your existing build scripts should work without modification.

For concrete examples of how I like to tie everything together, see my past answers, e.g.:

My way is not the only way, but I can attest that it works better than all the other variations I've encountered over the years :)

*Frankly, trying to micromanage Team Build can become a lot more painful than the proposed restructuring to your MSBuild scripts. For reliability you have to place your tfsbuildservice.exe.config customizations under version control somewhere...if you own >1 build server (or might in the future) then you have to consider a change deployment strategy...you end up needing a meta-SCM process to manage your SCM process!

Richard Berg
Thanks Richard. The trouble is we have a legacy build that does copies, obfuscation, installers and then a copy to the drop folder after the build - so (to save a lot of work) I really hoped to map the NewFeature code in place of the Main code. I'll add an answer below with my findings so far...
Jason Williams
Cheers for takig the time to add this detail, Richard. I'll have a good read through. I just want to sort out the TFS best practices before making massive changes, rather than going to a lot of effort and then finding out that it doesn't work that way either!
Jason Williams
Accepted answer, as your other answers exactly describe my planned branching structure, suggesting that I'm at least barking up the right tree :-)
Jason Williams
@Richard: I've just had another crack at this problem and actually solved it cleanly this time. It turns out you were spot on with your answer, it just took me a while to work out how to apply it :-) If you're interested, I've posted a new answer to this question detailing the situatin (in case somebody else strikes the same problem in future).
Jason Williams
A: 

OK, the results are in - I've found a workaround.

Due to our legacy build processes (build, copy, obfuscate, build custom installers, copy to drop folder), I can't easily place the branch alongside the main branch. It needs to replace it.

So, if I have Main and NewFeature, I wish to unmap Main and map NewFeature in its place (i.e. use "c:\Main" on the build server, and simply change the source code that appears there)

Solution #1 (the most simple, obvious and logical solution) is to use these mappings:

  • $/NewFeature -> c:\Main

Expected result: NewFeature code structure simply replaces Main, and the build server doesn't know it's on a different branch.

Actual Result: Failure with a "you haven't mapped $/Main even though you're not using it" error.

Solution #2 is to do this:

  • $/Main -> c:\IgnoreThisFolder
  • $/NewFeature -> c:\Main

This works (it suppresses the warning and thus allows the build to proceed with MSBuild unaware that it is building in a branch). However, it's ugly and the build gets all the Main branch source code unnecessarily.

Solution #3 (untested, too expensive to try unless I know it'll work much better than #2) is:

  • Move all the source code (from $/Main, $/Branches/Feature) to $/Branches/Main and $/Branches/Feature to get a consistent hierarchy depth, and rewrite the MSBuild script to work with these new paths.
  • Hope that I can then map in only the branch I need and edit TFSBuild.proj to redirect it to build in that branch.

Summary All these solutions (to use the technical term) suck. You have to remap the workspace (in this case, it's not simple: 9 mapping entries are required so it's an error prone and tedious thing to do), edit the TFSBuild.proj, delete all the source code, and run a build with /p:ForceGet=true to switch the build between branches. So it takes about an hour to switch branches. Unbelievable - it should take a few minutes at most!

I realise our project is far from ideally set up, but I can't believe it should be this difficult to branch in TFS (It was a piece of cake in SourceSafe, Accurev, and Perforce, so why so painful in TFS?).

How does everyone else organise their TFS branches? How do you switch developers between branches? How do you switch server builds between branches? Does it really have to be this painful?

Jason Williams
Edited my answer to (hopefully) address your pain points by example...
Richard Berg
A: 

New update:

As reported in the other answer, I found a workaround that was ok for a short-lived feature branch, but it really didn't work very well. I've since come back to the problem, and the full solution is ridiculously simple:

In the TFSBuild.proj, the path was based on $(BuildProjectFolderPath). This path resolves to a server-side (source control path) like $/Main - not a local path (D:\ServerBuildFolder\Main).

Unfortunately, for historical reasons our source code is split across several team projects, which means the one "branch" is fragmented into several branched folders in Source Control (i.e. $/Main/Code and $/Libraries/Code. You can't create a branch that contains $/Main and $/Libraries). We thus have to reassemble these disparate fragments from Source Control back into a coherent hierarchy using workspace mappings.

This means that Richard was spot on - the relative path from the TFSBuild.proj file to the .sln file was incorrect, because MSBuild/TFS is assuming that the .sln lies within the same Team Project and source control hierarchy (so was looking for $/Main/Libraries.sln instead of $/Libraries/Libraries.sln).

The solution is simple: I replaced $(BuildProjectFolderPath) with a local path (e.g. D:\ServerBuildFolder\Main) for the files, so that the relative reference was resolved in "local space" (after the mappings had been applied), and MSBuild is now running sweetly.

The moral of the story: 1) NEVER use more than one Team Project if there is any chance that you will ever wish to have any kind of reference between those code-bases. Don't be fooled into thinking that a new Team Project will offer some kind of painless logical distinction between applications/libraries. Extra projects have proven to just be an administration nightmare - loads of extra problems for absolutely zero benefit. (It's all one big shared pile under the bonnet, so all the work items and source control folders are still visible in all the projects (!), but it adds a few brick walls that make inter-project links very problematic)

2) Always create a single root-level folder in your Team Project source control, and then put everything else underneath that folder. e.g. For the project "$/Main", create "$/Main/Root" and then put everything from your source hierarchy inside Root.

By following these rules, you will be able to branch the single 'Root' folder in future, and will then only need a single branch and a single extra workspace mapping. This will help you avoid premature baldness.

(In my defence, I would have done it this way to begin with - I'm working with a legacy setup. In defence of the legacy setup, it sounds good on paper but just isn't a Microsoft-supported approach!)

Jason Williams
A: 

I also had this problem when running a build from a branch in TFS 2010. TFS was reporting that "There is no working folder mapping for $/Main/Product.sln" The solution turned out to be to edit the build definition as follows (I am using the "Default Template" build process template—I have not tried this with a custom template):

  1. Go to the Process section/tab of the build definition.
  2. Expand 1. Required and look for Projects to Build. Make sure this entry is pointing to the solution file inside the branch you are building.
  3. Expand 2. Basic and look for Automated Tests. Point this to the correct test settings file in the branch being built.

related questions