When we need to add custom settings or sections to the web.config file of a web application in WSS3 and MOSS, there is a way to do this quite automatically.
If you need several settings that you would like to have added to the web application's web.config when creating/extending the web application, custom xml config files can be used for this.
You can create a file in the format webconfig.[name].xml, put it in the \\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG folder and the settings in the file will be merged with the web.config file on any new web application.
Of course if your web application is already created and you put the file in the \config folder no changes are applied. This is really only when creating/extending new web applications.
Even so, this is a very interesting feature as you can automate any custom settings you would like on all your web applications in WSS3.
In my case I needed a custom appSettings element and a new custom connection string. The XML to be used consists of elements placed into the <actions> elements. The syntax is straightforward:
webconfig.myname.xml contents:
<?
xml version="1.0" encoding="utf-8" ?>
<
actions>
<
add path="configuration/appSettings">
<
add key="MyFilePath" value="C:\temp\path\" />
</
add>
<
add path="configuration">
<
connectionStrings />
</
add>
<
add path="configuration/connectionStrings">
<
remove name="MySqlServerConnection" />
<
add name="MySqlServerConnection" connectionString="server=[server];database=[db];Integrated Security=SSIP;" providerName="System.Data.SqlClient" />
</
add>
</
actions>
To deploy this file to the CONFIG you can manually copy the file.
Another approach is adding the file to a solution. A file to be deployed to the CONFIG folder can be inserted by using the <RootFile> element:
manifest.xml example:
<
Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="GUIDHERE">
<
RootFiles>
<
RootFile Location="CONFIG\webconfig.myname.xml"/>
</
RootFiles>
<!--
rest of solution manifest here
<FeatureManifests>... and other elements
-->
</
Solution>
This is my approach to automating web.config settings. Just remember the config settings are only merged with the web.config file when you create a new web application, nothing is changed on existing web applications.
Contrary to the <SafeControls> elements you can use in a solution manifest, these are always merged to the web.config file when you deploy the solution.
MSDN reference for custom configuration settings: http://msdn2.microsoft.com/en-gb/library/ms439965.aspx