Update multiple *.configs

I have a case where I have multiple configs of varying types in many projects within the one solution - e.g. web.config; app.config; logging.config and so on.

I have a need to update a number of appSettings that fit with the CI environment so that unit/integration tests will use appropriate values. Up to now I have used the File Content Replacer but I am finding it increasingly brittle if, say, a subtle change is made to the source xml fragment e.g. changing this <add key="someKey" value="someValue"/> to this: <add key="someKey" value="someValue" />.

e.g. 

Replace: <add key="someKey" value="Existing value with no trailing space"/>
With this: <add key="someKey" value="[Always fails]>

Is there an alternative to the File Content Replacer, something like update [value] where [key] name matches xyz?

Failing that, is there a better way I could be using the File Content Replacer?

Currently running TeamCity Professional v10.0.5 (build 42677)

Any tips/pointers would be very much appreciated.

0
2 comments
Avatar
Permanently deleted user
Official comment

Hi Roddy,

If I understand your problem correctly, you just need to start using regular expressions instead of fixed strings in your Find what and Replace with fields.

Given the use case you've described above, I'd replace the following expression:

(\<\s*add\s+key=\"someKey\"\s+value\s*=\s*)\"([^"]+)\"

with

\1"The new value attribute here"

There're great resources available on-line to test your regular expressions before you use them, such as https://regex101.com/.

 

Regards,
Andrey.

Avatar
Permanently deleted user

Hi Andrey

Thank you so much for this! The RegEx provided works perfectly and is exactly what I am looking for. The reg101.com resource is also proving very useful.

Thanks again,

Roddy.

0

Please sign in to leave a comment.