Print Page | Close Window

Web.config transformation

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2805
Printed Date: 28-Mar-2024 at 5:35am


Topic: Web.config transformation
Posted By: scottarlp
Subject: Web.config transformation
Date Posted: 30-Jun-2011 at 1:23pm
Does anyone have an example of the transformation of the web.config for the objectServer? I can transform elements of the config except for the IdeaBlade section. It has something to do with the custom section name, but I can't figure out a syntax to make it work. The xdt: elements are unknown within the ideablade section.
 
Example web.config (shortened). Here's the original.

<configuration>
<section name="ideablade.configuration" type="IdeaBlade.Core.Configuration.IdeaBladeSection, IdeaBlade.Core" />
</configSections>

<ideablade.configuration version="6.00" xmlns=" http://schemas.ideablade.com/2010/IdeaBladeConfig - http://schemas.ideablade.com/2010/IdeaBladeConfig ">
<objectServer serviceName="EntityService.svc" remoteBaseURL=" http://localhost - http://localhost " serverPort="80">
<clientSettings isDistributed="true" />
</objectServer>
</ideablade.configuration>

</configuration>

Then I want to do a transformation basically to change the remoteBaseURL when I publish.

<configuration xmlns:xdt=" http://schemas.microsoft.com/XML-Document-Transform - http://schemas.microsoft.com/XML-Document-Transform ">
<configSections>
<section name="ideablade.configuration" type="IdeaBlade.Core.Configuration.IdeaBladeSection, IdeaBlade.Core"/>
</configSections>

<ideablade.configuration version="6.00" xmlns=" http://schemas.ideablade.com/2010/IdeaBladeConfig - http://schemas.ideablade.com/2010/IdeaBladeConfig ">
<objectServer serviceName="EntityService.svc" remoteBaseURL=" http://server - http://server " serverPort="80"
xdt:Transform="Replace" xdt:"Match(serviceName)">
<clientSettings isDistributed="true" />
</objectServer>
</ideablade.configuration>

</configuration>

 




Replies:
Posted By: robertg
Date Posted: 07-Jul-2011 at 11:41am
I'm no expert in this, but doesn't your locator declaration  need to be something like xdt:Locator="Match(serviceName)" />?


Posted By: scottarlp
Date Posted: 07-Jul-2011 at 11:49am
Yes, sorry, when I was trying to copy/paste and protect the innocent, I accidently left that out of my example config. I'm kind of amazed that given VS2010 being out for a while and this built in studio feature being a god send for deployment that IB hasn't shown something about it somewhere. I'm no pro on all the XML tag definitions, so I'm not sure what to even google for IB's custom XML section and how it interfaces with another section (the transformation).
 
 


Posted By: robertg
Date Posted: 07-Jul-2011 at 12:21pm
Oh, I see! I'm reading the MSDN documentation on this right now, and it turns out that the Locator is optional anyway (who knew?), so I think we can simplify things by leaving it out. Also, it looks like since you just want to replace one attribute, we probably want to use the appropriate declaration, rather than trying to replace the entire object.
 
So, I think we could try something like this:
 
<configuration xmlns:xdt=" http://schemas.microsoft.com/XML-Document-Transform - http://schemas.microsoft.com/XML-Document-Transform ">
    <ideablade.configuration>
        <objectServer 
            remoteBaseURL=" http://www.newserveraddress.com/ -
            xdt:Transform="SetAttributes(remoteBaseUrl)">
            />
    </ideablade.configuration>
</configuration>
 
That way, we should be specifying that we want to transform the remoteBaseUrl property of ideablade.configuration.objectserver, and leaving everything else as it is.
 
 
Edit: Testing, and this doesn't work as expected. I'm mucking with it now and will post when it does work.


Posted By: robertg
Date Posted: 07-Jul-2011 at 3:01pm

I found the problem, and it seems to be with the version and xmlns statements in the config file. When I remove them, and have sections that look like this, the transformation works:

 
From my Web.Config:

<ideablade.configuration>
    <objectServer serviceName="EntityService.svc" remoteBaseURL=" http://www.oldserveraddress.com/ - http://www.oldserveraddress.com/ " />
</ideablade.configuration>

 
From my Web.Release.Config:
 
<ideablade.configuration>
    <objectServer serviceName="EntityService.svc"
        remoteBaseURL=http://www.newserveraddress.com/
        xdt:Transform="SetAttributes()" xdt:Locator="Match(serviceName)"/>
</ideablade.configuration>

 
We'll open a defect to try to determine why the transformation won't work when the xmlns is declared, but in the meanwhile, this seems to be the way to do it.


Posted By: mgood
Date Posted: 18-Aug-2011 at 3:06pm
I was just messing around with this when I came across this post and thought I add my 2 cents.
 
The Web.config transformation files need to use the correct namespace for the ideablade section. So, if you have this in your web.config for example:
 
	<ideablade.configuration version="6.00" xmlns= http://schemas.ideablade.com/2010/IdeaBladeConfig - http://schemas.ideablade.com/2010/IdeaBladeConfig >
		<edmKeys>
			<!-- Security EDM Key -->
			<edmKey name="Security" connection="..." />
		</edmKeys>
	</ideablade.configuration>
 
And say you want to replace the connection string in that edmKey, the transformation file would look like this:
 
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
 
 
  <ideablade.configuration version="6.00" xmlns= http://schemas.ideablade.com/2010/IdeaBladeConfig - http://schemas.ideablade.com/2010/IdeaBladeConfig >
 
    <edmKeys>
      <edmKey name="Security" 
                 connection="..."
                 xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
 
    </edmKeys>
  </ideablade.configuration>
 
 
</configuration>
 
This transformation works when you actually build the deployment package, but IntelliSense complains about xdt:Transform and xdt:Locator not being defined. At this point it looks like a bug in IntelliSense. As I said the transformations do actually work.
 
 



Print Page | Close Window