0

How to add PostBuild commands for the web.config xdt transformation so that when a build is queued successfully it will transform the web.config as per the web.platform.config xdt commands.

If the build branch is e.g. OnlineManagement_Dev then the transformation should happen based on the web.debug.config when I queue this branch . If the build branch is e.g. OnlineManagement_UAT then the transformation should happen based on the web.UAT.config when I queue this branch . If the build branch is e.g. OnlineManagement_PROD then the transformation should happen based on the web.PROD.config when I queue this branch .

I tried looking at the below solution but looks like 'TransformXml' task has a file lock bug. Is there any update to the MSBuild which provides a simpler and better solution than this ?

http://www.diaryofaninja.com/blog/2011/09/14/using-custom-webconfig-transformations-in-msbuild

1 Answer 1

2

1) The FileLock "bug" is addressed in the code sample in the section where they explain the bug before including the work around.

2) Do you have an environment variable and/or an MsBuild property that contains the branch type? If so, simply use that to determine source.

e.g.

<TransformXml Source="web.UAT.config"
  Transform="TransformFile.config"
  Destination="Web.config"
  StackTrace="true" />

Update the Source using the name of the environment variable or MSBuild Property that contains this value.

<TransformXml Source="web.$(EnvironmentType).config"
  Transform="TransformFile.config"
  Destination="Web.config"
  StackTrace="true" />

Note that if you are building from a command prompt and already have this in an environment variable, wrap the ENVIRONMENT_VARIABLE_NAME like this $(ENVIRONMENT_VARIABLE_NAME), and MsBuild will identify it.

Sign up to request clarification or add additional context in comments.

2 Comments

I always queue the build from the Team Explorer. And I see the build definition has some variables. Are you talking about the varibles in the description of Build definition ? I think its a good idea to add a variable in the build definition rather than in the .cs proj because when code gets merged to UAT / PROD branch then we don't have to worry about this environment variable . Isn't it ?
Try building this with logging set to "debug" verbosity. When you do this, the MsBuild log with have a very lengthy preamble containing a list of all environment variables as well as any MsBuild properties and their values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.