I created a little PowerShell script to change connection string in my web.config.
param([string]$webConfigPath, [string]$connectionStringName, [string]$connectionStringValue)
# get the full path of the web config file
$webConfigFile = [IO.Path]::Combine($webConfigPath, 'Web.config')
# load the XML
$webConfig = [xml](cat $webConfigFile)
#change the appropriate config
$webConfig.configuration.connectionStrings.add | foreach {
if($_.name -eq $connectionStringName){
$_.connectionString = $connectionStringValue
}
}
#save the file
$webConfig.Save($webConfigFile)
I added it to my build process. How to pass the build's variables to the script?
(I use the new script based build process, so I only have a builtin "Arguments" field for the parameter)
You can put all parameters in a single line into Arguments files like this:
-webConfigPath "c:\web.config" -connectionStringName "My connection string"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With