Water Cooler v2
Water Cooler v2

Reputation: 33850

How do I make these two web.config transforms to work?

I created a configuration named Local and I want my web.local.config to be transformed thus:

1. Connection String

My web.config has the following connection string:

<connectionStrings>
    <add name="Entities" 
         connectionString = "dummy"
         providerName="System.Data.EntityClient" />
</connectionStrings>

I would like my web.local.config to have the following, though:

<connectionStrings>
  <add name="Entities"
     connectionString="What a nice connection string!"
     providerName="System.Data.EntityClient" />
</connectionStrings>

I have presently set my transform thus:

<connectionStrings>
<add name="Entities"
     connectionString="What a nice connection string!"
     xdt:Transform="SetAttributes"
     xdt:Locator="Match(name)"/>
</connectionStrings>

I have also tried the Replace transform as follows but that doesn't work either:

<connectionStrings>
  <add name="Entities"
    connectionString="What a nice connection string!"
         xdt:Transform="Replace"
         xdt:Locator="Match(name)"/>
</connectionStrings>

But I still get a format exception in Entity Framework when my DbContext object tries to initialize itself using my connection string.

2. App Settings

My web.config has the following app settings:

<appSettings>
    <add key="Nice" value="true" />
    <add key="NotNice" value="true" />

    <!-- I want only this one's value to change in my web.local.config -->
    <add key="foo" value ="I am a foo." />
</appSettings>

I would like to change just the value of the app setting whose key is foo so that my appSettings in my web.local.config looks as follows:

<appSettings>
    <add key="Nice" value="true" />
    <add key="NotNice" value="true" />

    <!-- I want only this one's value to change in my web.local.config -->
    <add key="foo" value ="Are you also a foo?" />
</appSettings>

My presently applied transform looks like so:

<appSettings>
    <add key="foo" value = "Are you also a foo?"
     xdt:Transform="SetAttributes(value)"
     xdt:Locator="Match(key)"/>
</appSettings>

I have also tried the Replace transform as follows but that doesn't work either:

<appSettings>
  <add key="foo" value = "Are you also a foo?"
  xdt:Transform="Replace"
  xdt:Locator="Match(key)"/>
</appSettings>

But when I read the key foo from my appSettings when I run my Local configuration in debug mode, the code still reads the old value "I am a foo."

What am I doing wrong?

Upvotes: 1

Views: 304

Answers (1)

BigMuzzy
BigMuzzy

Reputation: 138

Have you tried to use "Preview Transform" feature? enter image description here

Also, check your project file to see if there are lines similar to these:

enter image description here

Please see SlowCheta Tool page for additional info.

Upvotes: 1

Related Questions