问题
I am using Release Manager 2015 to deploy my application.
I am using Microsoft's Extension Utilities pack to do this:
Extension Utility Pack - Documentation
This simply states:
Tokenization based pattern replacement
This task finds the pattern __<pattern>__ and replaces the same with the value from the variable with name <pattern>.
Eg. If you have a variable defined as foo with value bar,
on running this task on a file that contains __foo__ will be changed to bar.
So in my web.config.token file I simply add:
<add name="ADConnectionString" connectionString="__ADConnectionString__" />
and in release manager under variables created a variable with the name ADConnectionString which is then picked up during the step and replaced.
My question is that I cannot figure out a way to replace a tokenized string within a string.
<add name="CreateTextWriter" initializeData="directory=D:\__WEBLOGDIR__\__ENVIRONMENT__; basename=Web" />
This will work however
<host name="cache1.__ENVIRONMENT__.__DOMAIN__" cachePort="1"/>
will not. This is due to the RegEx being used for the matching.
$regex = '__[A-Za-z0-9._-]*__'
$matches = select-string -Path $tempFile -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value }
This will match the whole string rather than each tokenized string. To get around this I have changed the RegEx slightly to not be greedy in its selection.
$regex = '__[A-Za-z0-9._-]*?__'
Hope this helps someone else.
来源:https://stackoverflow.com/questions/38521298/tokenization-based-pattern-replacement-in-web-config-token