asp.netdeployment.net-4.0web-configweb-config-transform

Publish is not transforming web.config?


I made a web.config (full file, it doesn't show XML errors)

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
      ...
      <location path="." inheritInChildApplications="false">
        <connectionStrings>
          <add name="ElmahLog" connectionString="data source=~/App_Data/Error.db" />
          <add name="database" connectionString="w" providerName="System.Data.EntityClient"/>
        </connectionStrings>
      </location>
  ...

with a transform file (web.Staging.config)

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="database"
      connectionString="c"
      providerName="System.Data.EntityClient"
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
    <customErrors defaultRedirect="error.aspx"
      mode="RemoteOnly" xdt:Transform="Replace">
    </customErrors>
  </system.web>
</configuration>

I am publishing in Staging mode (right click website > Publish > Method: File System ...)

------ Build started: Project: Drawing, Configuration: Staging Any CPU ------
  Drawing -> D:\Project\bin\Staging\Drawing.dll
------ Build started: Project: MySystem, Configuration: Staging Any CPU ------
  MySystem -> D:\Project\bin\Staging\MySystem.dll
...

But when I look at the web.config in the output folder it isn't changed.

I found the following on the Build log:

D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
D:\Project\Web.Staging.config(3,2): Warning : No element in the source document matches '/configuration'
Transformed web.config using Web.Staging.config into obj\Staging\TransformWebConfig\transformed\web.config.

What could be the problem? Am I doing this right?


Solution

  • I found out two things:

    Like

    <configuration>
      <location>
        <connectionStrings>
    

    Instead of

    <configuration>
      <connectionStrings>