2

I am attempting to setup Team City for CI on my project. We currently have 9 developers working on the project and using Mercurial for source control. Right now all web.config files are ignored in the main project repo and the web.config files are located in a separate repo so that we do not have to use a dozen transforms.

How can I configure Team City/MS Build so I can checkout both repos (have this working so far) and then update the repos and copy the web.config to the main project folder before doing the build?

jpshook
  • 4,516
  • 6
  • 34
  • 44
  • Can you use a hg pull request using a command line build step, and use a second command line build step to copy the web.config? – Jonathan McIntire Mar 05 '12 at 20:03
  • @jmac - I am still trying to figure out the ins and outs of Team City. I am just looking for the best solution and how to actually implement it. – jpshook Mar 05 '12 at 21:45

2 Answers2

3

What you actually want to do is:
Each developer has his own web.config, but you want the build to use the same "central" web.config each time and ignore the developers' own web.config versions.
Correct?

If yes, I would do it a different way:
You can let the developers use their own web.config files by default, but still put the "central" web.config into the main project repository with a different file name (for example, web.config.build.
Then you can use BeforeBuild (in the .csproj file) in a way so that it will be automatically copied to web.config when there is no web.config file present (which should be the case on the build server, but not on the developer machines).

Read this answer to see how I'm doing something similar:
how to ignore files in kiln/mercurial using tortoise hg “that are part of the repository”

Community
  • 1
  • 1
Christian Specht
  • 33,837
  • 14
  • 123
  • 176
  • Thanks for your answer. +1 for novel solution. Might just work if I cannot find any better alternatives. – jpshook Mar 05 '12 at 21:58
  • Can I use this same technique to copy the file from a different folder outside of the repo? Also, when I browse to the checked out repo in the team city folder, the files don't show up, so I would need to also do a hg update or something before the copy. Not sure how TC is building without doing a hg update. – jpshook Mar 06 '12 at 18:29
  • @Developr: yes, you *could* copy the file from an external folder as well, but why do it like this if you can have the file in source control instead? Concerning "the files don't show up": I don't remember the exact setting now, but I'm sure that you can configure TeamCity so that it does a complete new clone on each build. I'm 100% sure that I configured our TeamCity at work like that. – Christian Specht Mar 06 '12 at 21:41
  • I used a version of your technique to get it to work in TeamCity. Unfortunately, I was not able to get the BeforeBuild target working, but I did just enter some command line arguments in the Pre build config instead. Even though your answer doesn't really solve my original requirements, it is a valid work around with minimal compromise, so I have marked it as the answer. – jpshook Mar 08 '12 at 15:10
  • Okay, maybe it's different in a web project. I'm not a web guy, and the code in the answer linked above was copied from an actual project of mine, but it's a command line app (that's why I'm copying `app.config` and not `web.config`). – Christian Specht Mar 08 '12 at 15:18
0

You can create a second VCS root and have it 'merge' files in your checkout on the teamcity machine

  • create a second VCS root in teamcity
  • append ignore rules to match only your *.config file as needed and place it in the correct folder

example ignore pattern from the top of my head:

-:* 
+:web.build.config=>website/

But i would suggest you follow the approach of Christian Specht because when you have a web.example.config which you copy to web.config on pre-build event you are able to modify it with new settings. This will get picked up easily by teamcity because you can have it 'clean' the directory (with Swabra) to remove the 'old' web.config file and get it re-copied from the (new) web.example.config

Mark van Straten
  • 8,503
  • 2
  • 34
  • 56
  • Where are the files located that team city builds from? I see where it clones the repo to, but not where it stores the files before build. – jpshook Mar 07 '12 at 13:10