Using Microsoft's xml document transform to transform web.config is adding unwanted whitespace
I'm using an XML-Document-Transform to transform my web.config file for deployment to a staging server. Unfortunately it isn't transforming exactly as specified and is adding some whitespace to an element's text. This whitespace is then being picked up by the Castle Windsor configuration that I use and bombing the application.
Here's an example:
web.config:
<configuration>
<castle>
<properties>
<serverUrl>http://test</serverUrl>
<properties>
<components>
<component id="MyService">
<parameters>
<Url>#{serverUrl}/MyService.asmx</Url>
</parameters>
</component>
</components>
<castle>
<configuration>
web.staging.config:
<configuration>
<castle>
<properties>
<serverUrl xdt:Transform="Replace">http://staging</serverUrl>
<properties>
<castle>
<configuration>
Output web.config:
<configuration>
<castle>
<properties>
<serverUrl>http://staging
</serverUrl>
<properties>
开发者_高级运维 <components>
<component id="MyService">
<parameters>
<Url>#{serverUrl}/MyService.asmx</Url>
</parameters>
</component>
</components>
<castle>
<configuration>
As you can see additional whitespace has been inserted in to the serverUrl
element by the transformation.
Unfortunately Castle includes the whitespace when inserting the serverUrl
into the Url
of the service which creates an invalid URL.
Anyone else come across this? Anyone got a solution that still uses the new Microsoft transformation method but doesn't cause additional whitespace to be inserted?
IMHO this is a bug in the transform process although Castle should probably be ignoring the whitespace too.
Many thanks, Rob
This is fixed in Visual Studio 2010 SP1 and is an issue with Microsoft.Web.Publishing.Tasks.dll and related *.target files. If you are using a build server that does not have Visual Studio SP1 installed but is using MsBuild then you should ensure that you copy these files.
To resolve this issue copy everything from a machine with SP1 installed from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web to the same directory on the build server.
This issue also affects applicationSettings, but I was able to work around it by trimming the white space as you suggested. Here's my Settings.cs file.
internal sealed partial class Settings
{
public override object this[string propertyName]
{
get
{
// trim the value if it's a string
string value = base[propertyName] as string;
if (value != null)
{
return value.Trim();
}
return base[propertyName];
}
set { base[propertyName] = value; }
}
}
I'm afraid this won't help your issue with Castle, but perhaps it will help someone else!
精彩评论