locked
Changing ".config" files in a project before TF Build RRS feed

  • Question

  • Hi there!

    Is it possible to change the files named ".config" in a solution just before a Team Foundation Team Build? The changes are not meant to be permanent, since it can be different from build to build.

    I have created a custom build activity for the TF Build and then I have done it the following:

    • First check if the config files exists
    • Then check out all the files for edit
    • Finally editing the files according to an specification file

    Unfortunately I am then faced with the problem that all these files are checked out for edit, but never checked in since this unwanted.
    I have tried with another activity that undo's pending changes for the build agent, but no matter where I place this activity the editing of the files doesn't persist after the build is finished.

    Does anybody know how to deal with this problem or have faced something similar?

    Kind Regards
    Christian





    Wednesday, April 23, 2014 1:59 PM

Answers

  • Hi Christian,

    We have done it in quite a lot of our builds. The way we do is to "Tokenize" the configuration file before it gets to web deploy or is packaged in a cab. The "tokenization" process replaces texts such as connection string, users, etc. with their respective tokens. If you are using Default template, you may like to use the "File" activity with action "Replace" in the TFS Build Extensions library. Once files are tokenized, the deployment process would detokenize it.

    In your case, you want to replace the connection string etc with values passed as build parameters, so your replacement tokens would be the build properties passed as MSBuild Arguments.

    Wednesday, April 30, 2014 3:31 PM

All replies

  • Hi Christian, 

    Thanks for your post.

    After you changed the .config file, you want check-in this updated .config file back to TFS Source Control or not?

    And I want to know why you need to change the .config file before Team Build in build process template? Generally, we should edit the files from Source Control Explorer and check-in the changes into TFS Source Control.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 24, 2014 8:52 AM
    Moderator
  • Thank you for you quick response.

    The idea is that these config files are changed to fit a specific environment where the packages created are to be delivered to, which can be different from time to time when the project is build.

    This could be connection strings which would be different or something along those lines.

    We want it to be done dynamically, such that it is just a parameter change for the environment in the build definition and then the config files are changed such that it fits the specific environment. These changes should not be permanent, but just temporary until the build and delivery is finished.
    Just to clarify, it is not the intention to check in the .config files since it is just temporary changes.


    • Edited by PS Christian Friday, April 25, 2014 1:25 PM More specific reply
    Friday, April 25, 2014 11:18 AM
  • Hi Christian,

    I still can't better understand why you want to use config files to configure build environment variables. Please give me more information on it. And if you just check out that file and edit it but don't check in, the TFS build system will just use the "old" checked in version, as pending changes in that file are in your local machine which are unavailable on the server machine. So for your scenario you have to check in the file.

    By the way, if you have different lab environments for the TFS builds, you need to choose to use the LabDefault template. If you want to change to use another environment, you just need to change the Environment name to another environment in the build process template.

    Thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 28, 2014 6:59 AM
    Moderator
  • Hi Christian,

    We have done it in quite a lot of our builds. The way we do is to "Tokenize" the configuration file before it gets to web deploy or is packaged in a cab. The "tokenization" process replaces texts such as connection string, users, etc. with their respective tokens. If you are using Default template, you may like to use the "File" activity with action "Replace" in the TFS Build Extensions library. Once files are tokenized, the deployment process would detokenize it.

    In your case, you want to replace the connection string etc with values passed as build parameters, so your replacement tokens would be the build properties passed as MSBuild Arguments.

    Wednesday, April 30, 2014 3:31 PM