TFS build-server build of branch?
Asked Answered
W

6

12

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?

Wrac answered 2/12, 2009 at 16:11 Comment(0)
S
9

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!

Southsouthwest answered 2/12, 2009 at 21:12 Comment(6)
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...Wrac
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!Wrac
Accepted answer, as your other answers exactly describe my planned branching structure, suggesting that I'm at least barking up the right tree :-)Wrac
@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).Wrac
I know this is old, but I am also having the same problem, trying to build a branch I downloaded from my TFS 2012 server. Although the branch is MyProject_v1_0_0_1, when I queue a TFS build, TFS complains and says: There is no working folder mapping for $/MyProject/Main/Project.sln. How do I "$(SolutionToBuild) uses a relative path when referencing Product.sln"? Thanks.Blacktop
BTW, MyProject_v1_0_0_1 is mapped to c:\dev\MyProject_v1_0_0_1, not c:\dev\MyProject at all.Blacktop
K
9

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.
Kempe answered 26/10, 2010 at 21:42 Comment(0)
W
3

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.

    (Edit: Yes, this works well. We have now reorganised our entire code structure so that everything (all branches) is under a common root in a single Team Project, and branching/building is no longer a problem - it's easy to do whatever we need now. The trick is to insert a root folder into the hierarchy so that you can branch at any level you like. I've added a small tweak to the build script so that we can pass the branch to build as a parameter to MSBuild, so it's easy to build any variant now. Any branches we don't want to work on can just be cloaked and the build server remains happy.)

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?

Wrac answered 3/12, 2009 at 10:32 Comment(0)
M
2

When you Edit the build definition there are two places that need to be changed.

  1. Source Settings - Point to your new project location
  2. Process - (This sometimes takes a while to load so be patient) Under Required, change the "items to build" location to the new solution.

Hope this helps.

Manor answered 13/1, 2014 at 16:20 Comment(0)
W
0

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!)

Wrac answered 26/3, 2010 at 14:33 Comment(0)
D
0

I got this error and all I can fathom is that the definition became corrupt or something. I just redid the process stuff (re-added the solution I was trying to build) and remapped the workspaces and it started working again. HTH.

Dariodariole answered 13/9, 2012 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.