So today, or last night rather, I finally got down to seriously look at this wonder trinket the ASP.NET team provided as a cool add-in project for Visual Studio - Web Deployment Projects. The one true feature that really had me excited was the ability to define multiple sections in web.config as replaceable, so different builds for different environments is possible from a single project-control point. Have staging, UAT, production environments? Just define the sections that need to be replaced with the contents of a replacement file carrying environment-specific configuration settings. Sweet.
However, savouring this delicious taste proved to be highly elusive. Initially I was confused where to locate these replacement files. Do I place them in the WDP project's own directory? There weren't any clear instructions or information about this, so it took me awhile to figure out it had to be placed in a sub-directory in the source web site. Technically, these files can reside in the web site document root but that just makes that area messy. So having nailed that issue down I went about the business of defining all sections that ought to go through facelifts.
All goes through except the last entry. <system.net> despite being right there in the config file is met with a lost Visual Studio complaining of the subject-mentioned error message. I tried many things, even narrowing down to
but it still wouldn't give me joy. Apparently few people use WDPs to configure <system.net> settings and I kept digging out the same threads of other people's similar problems. And no real answer. It wasn't until I decided to throw a tantrum and watch some anime did I then gave it a more thoughtful read over this thread that made me take a look at C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config out of random curiosity. Seemingly, WDP does not like replacing section groups.
And there it stood:
<sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="authenticationModules" type="System.Net.Configuration.AuthenticationModulesSection, System, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="connectionManagement" type="System.Net.Configuration.ConnectionManagementSection, System, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<sectionGroup name="mailSettings" type="System.Net.Configuration.MailSettingsSectionGroup, System, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="smtp" type="System.Net.Configuration.SmtpSection, System, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<mailSettings> is a section group itself. One would have to drill down to the <smtp> section to make a proper replacement.