Search code examples
c#selenium-webdrivertfsmsbuildmsbuild-task

How to update either App.Config file before the build starts based on a param


I am writing a MSTest based unit testing framework to run Selenium tests. I am supplying the browser on which the tests should run from the app.config file. The issue I am facing is I need to run the test on all kinds of Browsers on an ad-hoc basis. This is determined by the value for the key browser.

<appSettings>
   <add key="browser" value="chrome"/>
</appSettings>

If I need to run this in another browser, I will update the browser value to Firefox and all is fine.

But when it comes to an CI environment, is there a provision to update the app.config file outside the code and then trigger the build.

Since I am using TFS, Is there a build task which can update the app.config or is there a param which I can pass in MSBUILD.exe

In this scenario, any person who triggers the build can determine the browser in which they have to run the test and trigger the test.

Any pointers will be of much help for me.


Solution

  • Yes, you can download Replace Tokens build task extension and install it in your TFS. Then you can add it in your build definition before VSBuild step. This task can replace the string in the file with the value of variables. You just need to change the value of the variable when queue the build.