Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Config Transformation Syntax

I've been following the MSDN guide for Web Config Transformation and by-and-large have had success with it.

However, one line of my web config is giving my troubles and I can only assume it's because I'm misunderstanding the guide and using the wrong syntax.

I'm hopeful that someone will be able to point out my mistake, and will be grateful if that's the case.

The offending line in the transform is:

<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />

The line in the original web config is:

<sessionState mode="SQLServer" sqlConnectionString="data source=networkAlias;uid=userId;pwd=password;" cookieless="UseDeviceProfile" timeout="120" />

My hope was that the transform would replace the attribute "sqlConnectionString", changing the connection details. Unfortunately the line is unaffected.

I've used exactly the same syntax for:

<network host="localhost" xdt:Transform="SetAttributes(host)" />

The above works just fine, so I had assumed it would be the case for the too.

Can anyone see where I'm going wrong?

like image 981
Jonathan Avatar asked Oct 28 '11 12:10

Jonathan


People also ask

How do I create a web config transform?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

How does web config transform work?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I rename a web config transform?

If you are using the extension Configuration Transform go to Build > Configuration Manager and find the Configuration dropdown for the project of which you want to change the app config. You can then select the edit and rename the build configurations for that project.


2 Answers

Just a simple typo. You need to change sqlConnectionString to stateConnectionString. You have it right in the web.config, but not the transformation. Otherwise, the transform looks good.

You need to change sqlConnectionString here:

<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />

To stateConnectionString:

<sessionState stateConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(stateConnectionString)" />
like image 186
Doozer Blake Avatar answered Sep 23 '22 05:09

Doozer Blake


After taking a break and coming back to it with some fresh eyes, I realised that the syntax was in fact just fine.

The problem was that at some point - no idea when - the element had been moved (maybe a copy/paste error by myself or another team member) out of the element where it belonged, so it was just hanging there and not where it should have been.

Once I moved back into where it should have been, problem solved, the transform was correctly detecting the element again and applying the transform.

So, lesson learned: if a transform is mysteriously not being applied to one element (when it works just fine on another), check to make sure the element is correctly situated.

like image 45
Jonathan Avatar answered Sep 21 '22 05:09

Jonathan