Setting the value of an attribute on an XML element
Although settings can often be configured by adding entire elements, others can be configured by setting an attribute on an already existing element. For example, we can replace a default database connection string by setting the connectionString
attribute on an add
element. By doing it at installation time, we're given the flexibility to collect the connection details from the user or base them on the environment in which the installer is running. In this recipe, we'll see how to use the XmlConfig
element to change a default connection string to something else.
Getting ready
To prepare for this recipe, perform the following steps:
Create a new setup project and name it
XmlAttributeInstaller
.Add an XML file to the project and call it
Web.config
. Add the following markup to it:<?xml version="1.0"?> <configuration> <appSettings /> <connectionStrings> <add name="mydb" providerName="System.Data.SqlClient" connectionString...