Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2013 Web.Config transformation - How to disable automatic formatting/line breaks?

We are currently using VS 2013 to develop asp.net (silverlight) applications for multiple environments (dev/test/quality assurance/prod), and are currently using web transformation functionality when we publish builds.

We have some lines that are extremely long in the master web.config (as in 400+ columns). We realize that for readability sake the proper approach should be to split these into multiple lines, but in our particular case we would prefer that they remain long as they are.

So, the problem is that if you publish and point to one of the publish profiles utilizing a web transform, the resulting Web.Config file will not retain the one long line. During the transformation it is automatically split (word-wrapped) across multiple lines for easier readability. I understand why Microsoft does this, but I thought for sure there would be a simple setting somewhere where we could disable any "automatic formatting", "auto word-wrap", etc.. However I have not had any luck finding it.

Another way to see the behavior without going through the trouble of a full publish would be if you right-click, for instance, Web.Test.Config, under the main Web.Config entry in solution explorer, and select "Preview Transform". Here you will be able to clearly see how the transformed version is auto-formatting and putting line breaks in place for lines in the main Web.Config that goes past a certain number of characters. We would like to turn off this behavior if possible...we only want actual values changed/transformed, not the formatting.

Does anyone know if this is possible, and if so, how to accomplish it? Was it just some simple setting we missed?

Finally - a couple of quick examples. If I run a "preview transform" to preview changes when transforming from our main Web.Config to our Web.Test.Config, I see the following behaviors:

this line in the main web.config:

<add verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX"/>

gets turned into this in the final published web.config:

<add verb="*" path="Reserved.ReportViewerWebControl.axd"
type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXXXXXXXXX"/>

and this line in the main web.config:

<sessionState timeout="300"></sessionState>

gets turned into this in the final published web.config:

<sessionState timeout="300">
</sessionState>

thanks in advance for any help at all you can provide.

like image 846
friskyweasel Avatar asked Dec 05 '25 03:12

friskyweasel


1 Answers

You can disable automatic formatting/line breaks in Visual Studio 2013's Web.config transformation by adding the following attribute to the element in your Web.config file: xml:space="preserve". This will preserve the white space in your Web.config file during a transformation.

like image 93
Tabby Avatar answered Dec 07 '25 20:12

Tabby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!