7

I use the new VS 2010 configuration transformations to deploy websites. To replace a single setting of my ApplicationSettings I use the following configuration transformation:

<setting name="TempPath" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
    <value>C:\TEMP</value>
</setting>

Remark: There is no white space between C:\TEMP and the end tag

This transformation results in a setting with unwanted white space like this:

<setting name="TempPath" serializeAs="String">
    <value>C:\TEMP
    </value>
</setting>

If I use this setting without trimming it, I get faulty behaviour.

Any idea?

Dirk Brockhaus
  • 4,922
  • 3
  • 38
  • 47

3 Answers3

6

This is a known problem of VS 2010. According to Microsoft it will be fixed for the service pack and next release.

Update

The final release of the SP1 solves this problem. Workarounds to remove unwanted line feeds are no longer necessary.

Dirk Brockhaus
  • 4,922
  • 3
  • 38
  • 47
3

I just wanted to mention that there is a workaround posted on the MS connect issue page by john.rummell which worked flawlessly for me. Just add this to your project:

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; }
    }
}
BigJoe714
  • 6,732
  • 7
  • 46
  • 50
  • Late I recognized your answer. This workaround works for me too. A hint for VB.NET: The class name is MySettings. – Dirk Brockhaus Nov 30 '10 at 09:04
  • You need to make sure that the partial class is part of the same namespace as the original setting class. Usually this means adding .Properties to the namespace declaration for the partial class. – TGnat Feb 01 '11 at 19:54
0

The Xml formatting makes the space. as the content of an XML tags do not care about line breaks and whitespaces. if you want to have string values, i would strongly recommend to put it into attributes, instead of InnerValue

<setting name="TempPath" value="C:\TEMP">
</setting>
cRichter
  • 1,411
  • 7
  • 7