.net - Merging web.config and other .config files -
i dynamically add references webservices project , need add information them web.config.
svcutil gracefully adds config files containing "system.servicemodel" node , subnodes.
what i'm looking how merge information these files existing web.config. hoped 'configsource' attribute help, however, cannot used on "system.servicemodel" section group, on content of it. however, splitting "system.servicemodel" nodes configs require same or more parsing, comparing modifying web.config itself.
i wonder, if there options reuse data child config files in web.config? especially, when whole section group involved?
as no other solutions suggested, created function modify web.config manually , copy data smaller configs.
just in case finds useful or suggests better approach:
# changes web.config: adds system.servicemodel group data binding , endpoint webservice function add-config-source { param($configfile) if(($configfile -eq "") -or ($configfile -eq $null)) { $errors = $errors + " error: path webservice configuration file not found. "; } # data web service config file $webserviceconfigxml = [xml](get-content $configfile) # cloning elements need $bindingnodeclone = $webserviceconfigxml.selectsinglenode("//binding").clone(); $endpointnodeclone = $webserviceconfigxml.selectsinglenode("//endpoint").clone(); $servicemodelnodeclone = $webserviceconfigxml.selectsinglenode("//system.servicemodel").clone(); # reading , modifying web.config $webconfigxml = new-object xml # find web.config file $config = $project.projectitems | {$_.name -eq "web.config"} # find path on file system $localpath = $config.properties | {$_.name -eq "localpath"} # load web.config xml $webconfigxml.load($localpath.value) # select node $configurationnode = $webconfigxml.selectsinglenode("configuration") # check if 'system.servicemodel' node exists $servicemodelnode = $configurationnode.selectsinglenode("system.servicemodel"); if ($servicemodelnode -eq $null) { $servicemodelnodeclone = $webconfigxml.importnode($servicemodelnodeclone, $true); $configurationnode.appendchild($servicemodelnodeclone); } else { $existingbasichttpbindingnode = $servicemodelnode.selectsinglenode("//basichttpbinding"); $bindingnodeclone = $webconfigxml.importnode($bindingnodeclone, $true); $existingbasichttpbindingnode.appendchild($bindingnodeclone); $existingclientnode = $servicemodelnode.selectsinglenode("//client"); $endpointnodeclone = $webconfigxml.importnode($endpointnodeclone, $true); $existingclientnode.appendchild($endpointnodeclone); $configurationnode.appendchild($servicemodelnode); } # save web.config file $webconfigxml.save($localpath.value) }
Comments
Post a Comment