Visual studio 2010 使用微软&x27;s xml文档转换为转换web.config时添加了不需要的空白

Visual studio 2010 使用微软&x27;s xml文档转换为转换web.config时添加了不需要的空白,visual-studio-2010,deployment,transform,xslt,xml-document-transform,Visual Studio 2010,Deployment,Transform,Xslt,Xml Document Transform,我正在使用XML文档转换来转换web.config文件,以便部署到临时服务器。不幸的是,它没有完全按照指定的方式进行转换,并且在元素的文本中添加了一些空白。然后,我使用的Castle Windsor配置将拾取该空白并轰炸应用程序 下面是一个例子: web.config: <configuration> <castle> <properties> <serverUrl>http://test</serverUrl>

我正在使用XML文档转换来转换web.config文件,以便部署到临时服务器。不幸的是,它没有完全按照指定的方式进行转换,并且在元素的文本中添加了一些空白。然后,我使用的Castle Windsor配置将拾取该空白并轰炸应用程序

下面是一个例子:

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>
<configuration>
  <castle>
    <properties>
      <serverUrl>http://staging
      </serverUrl>
    <properties>
    <components>
      <component id="MyService">
        <parameters>
          <Url>#{serverUrl}/MyService.asmx</Url>
        </parameters>
      </component>
    </components>
  <castle>
<configuration>

http://test
#{serverUrl}/MyService.asmx
web.staging.config:

<configuration>
  <castle>
    <properties>
      <serverUrl xdt:Transform="Replace">http://staging</serverUrl>
    <properties>
  <castle>
<configuration>

http://staging
输出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>
<configuration>
  <castle>
    <properties>
      <serverUrl>http://staging
      </serverUrl>
    <properties>
    <components>
      <component id="MyService">
        <parameters>
          <Url>#{serverUrl}/MyService.asmx</Url>
        </parameters>
      </component>
    </components>
  <castle>
<configuration>

http://staging
#{serverUrl}/MyService.asmx
如您所见,通过转换,在
serverUrl
元素中插入了额外的空白

不幸的是,Castle在将
serverUrl
插入服务的
Url
时包含空格,这会创建无效的Url

还有谁见过这个吗?有人找到了一个仍然使用新的Microsoft转换方法但不会插入额外空格的解决方案吗

这是转换过程中的一个错误,尽管Castle可能也应该忽略空白

非常感谢,Rob

这个问题也会影响,但是我可以按照你的建议,通过修剪空白来解决这个问题。这是我的Settings.cs文件

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; }
    }
}

我担心这不会帮助你解决Castle的问题,但可能会帮助其他人

这在Visual Studio 2010 SP1中已修复,并且是Microsoft.Web.Publishing.Tasks.dll和相关的*.target文件的问题。如果使用的生成服务器未安装Visual Studio SP1,但使用的是MsBuild,则应确保复制这些文件


若要解决此问题,请将安装了SP1的计算机上的所有内容从C:\Program Files(x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web复制到生成服务器上的同一目录中。

我还尝试了移动
xdt:Transform=“Replace”
属性,并将所有子元素包括在转换中。不幸的是,这只会将空白添加到所有子元素中:(下一步将停止使用城堡属性…呜呜。这是一个已知的问题: