Search code examples
asp.netweb-config-transform

and the web.config transformation just won't work.... won't work grrrrr


I am using Visual Studio 2010. I have this web.config

<?xml version="1.0"?>
<configuration>
  <system.web>      
      <compilation debug="true" targetFramework="4.0" />
      <authorization>
        <allow roles="domain\allow" />
        <deny users="*" />
      </authorization>      
    </system.web>
</configuration>

Now I have gone to solution -> Configuration Manager and added a new configuration called "Production"

Now I came and right click on my web.config and clicked "Add Config Transforms"

Now I can see a file called web.Production.config

I go and add this to my file

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="FooDB" connectionString="Data Source=FooServer;Initial Catalog=FooDB;Integrated Security=True;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

Now when I build and publish my project I see an error message

Web.Production.config(17,4): Warning : No element in the source document matches '/configuration/connectionStrings'

Solution

  • Move connectionStrings to the main web.config. The only things that should appear in your production config are the transformations.