开发者

How to stop Visual Studio from wrapping lines when XML is auto-generated for service references

When you add or update a Service Reference in a Visual Studio project (formerly called a "Web Reference") VS.NET will auto-generate all the XML binding code in your application config.

It tends to look like this:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBindin开发者_开发问答g_IUserService" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
          <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://domain.com/services/user.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserService"
      contract="UserService.IUserService" name="BasicHttpBinding_IUserService" />
  </client>
</system.serviceModel>

I hate how messy that looks, and so I usually go through and manually "fix" it to remove all the line breaks.

So I make it look like this:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IUserService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None">
          <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
          <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://domain.com/services/user.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUserService" contract="UserService.IUserService" name="BasicHttpBinding_IUserService" />
  </client>
</system.serviceModel>

It's not just a matter of wanting it to look clean. Some of my client projects have upwards of 20 references so it helps keep the config from not having 10 feet of vertical scroll.

I've looked for options that would stop this but have never found any. This morning, it occurred to me that maybe I should ask SO about it. Other SO questions, such as this one, touched on similar issues but no solution yet.


I'm pretty sure you can do this. Under Option/Text Editor/XML there should be a setting called attribute spacing. I have the exact opposite setting. While you are there, expand the Wrap line settings and look at that one.


Un-checking the Auto-Format options in Tools > Options > XML > Formatting might help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜