How to make a change to a config file before build

I am tasked with setting up an automatic build and deployment system for my company. The current process is manual, and we want to change. I am currently evaluating TeamCity and Octopus Deploy. We work with Visual Studio(ASP.NET WebForms and MVC), C#.NET, and are using SourceGear Vault as our VCS.

I have set up two build configurations in TeamCity: one that builds when a change to the repository is detected, and the other deploys to the Octopus server. This has been working well for me.

One of the requirements is that a version number setting in a config file has the updated build number. This is used in various places in our sites, so the source files used match the deployed sites. Currently, this number is manually incremented before the files are moved to the web server.

I set up labeling, so the source files are at least labeled with the version number, but I need to find a way to change the setting so it is stored in source control when a build occurs. I won't know this number until the TeamCity server starts its process. So I'm trying to find a way to do this from TeamCity.

I think I can use a script in TeamCity to call the SourceGear Vault API, and make the version number change in the config file, but won't that trigger another build when that is checked in?

A background on our manual process:

  • Each developer has their own config files for each project that work to connect to local instances of db servers and other resources needed.
  • After a version of a project has been tested and vetted by higher powers, the project is published.
  • The software version number variable is manually incremented.
  • The published folder is compressed, then moved to the appropriate web server.
  • The published folder is then extracted to the appropriate location and renamed to match the version number.
  • The server specific config files and folders are then taken from the previous version's folder, and replaced in the new version's folder.
  • The debug setting in the web.config is set to false, and the IIS settings are updated.


I have managed to emulate this process almost completely using TeamCity and Octopus Deploy, with the exception of setting the new version number in an appsettings config file. Do you have any suggestions or insights to help me accomplish this? This system works for us otherwise.
2 comments
Comment actions Permalink

Hi Nick,

>I think I can use a script in TeamCity to call the SourceGear Vault API, and make the version number change in the config file, but won't that trigger another build when that is checked in?

To avoid build triggering you can configure trigger rules. For example exclude commits done by specific user or with specific commit.

Do you actually need to commit these changes to the repository? What will happen if for example builds start in parallel?
Probably you can insert build number to config files locally on TeamCity agent and publish the resulted files.
0
Comment actions Permalink

Having the version number in the repository was a requirement for me. I set up a powershell script to make the required changes to the repository, then used trigger rules so that particular build didn't initiate a build process. Thank you for letting me know about that feature, I missed it.

0

Please sign in to leave a comment.