Larry Grady
Larry Grady

Reputation: 519

Web.Config Transformation Not Working

Using VS 2k15, ASP.NET 4.5 My Transform is not working. I was looking in preview and the files are the same. Then I figured maybe I had to deploy to see transformation. So I set up a custom Deploy to my desktop, using the Deploy Configuration. Checked the web.config after publishing that, still matching the original.

Any idea what I'm doing wrong?

I know when I do the preview I get a warning at the top of the preview that says..."

These files have different encodings. Left file: Unicode (UTF-8) without signature. Right file: Unicode (UTF-8) with signature. You can resolve the difference by saving the right file with the encoding Unicode (UTF-8) without signature.

However, when I choose Save Options and save the Deploy file with no signature (so they're matching) the message still comes up. Just not sure what's going on. Any ideas why I can't this transform to work?

Web.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

  <appSettings>
      <add key="fileLibrary" value="c:\vsoProjects\localFiles\rlFileLibrary" />
  </appSettings>

  <connectionStrings>
      <add name="appConnString" connectionString="Data Source=(LocalDb);Initial Catalog=DevDB;User ID=*****;Password=*****;Connect Timeout=300" />
  </connectionStrings>

</configuration>

Web.ContDeploy.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

  <appSettings>
      <add key="fileLibrary" value="R:\rlFileLibrary" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
  </appSettings>

  <connectionStrings>
      <add name="appConnString" connectionString="Data Source=myserver.test.com;Initial Catalog=DeployDB;User ID=*****;Password=*****;Connect Timeout=300" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)"/>
  </connectionStrings>

  <system.web>
      <compilation xdt:Transform="RemoveAttributes(debug)" />    
  </system.web>

</configuration>

Upvotes: 1

Views: 1898

Answers (2)

Larry Grady
Larry Grady

Reputation: 519

I found the problem. This project was converted a while back from asp.net 2.x to 4.5.

The web.config still had an attribute up in the configuration section.

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
...
</configuration>

You can see it up top in the code I posted. I didn't realize it was still there. After all that time banging my head against my desk I just removed that attribute, preview transform, and voila it was there! Also deploys properly as well.

Upvotes: 1

Michel
Michel

Reputation: 23645

I'm not an expert on the transform, but my (working) transform for the appSettings key has this signature:

  <appSettings>
    <add key="datafolder" value="D:\sites\removedpath\App_Data\" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
  </appSettings>

which is slightly different than yours

Upvotes: 1

Related Questions