Search code examples
c#visual-studioweb-configapp-config

App.config readability for large string values


I have various keys in appSettings, and each of them have a long string which contains values like these:

<add key="rightsTable" value="{LibraryNames='xxx',Folders='xxx',UserNames='xxx',RoleDefinitionNames='xxx'} {LibraryNames='yyy',Folders='yyy',UserNames='yyy',RoleDefinitionNames='yyy'} {LibraryNames='zzz',Folders='zzz',UserNames='zzz',RoleDefinitionNames='zzz'}" />

Now, in the App.config, I rearrange the string like this for readability:

<add key="rightsTable" 
     value=
     " 
{LibraryNames='xxx',Folders='xxx',UserNames='xxx',RoleDefinitionNames='xxx'}
{LibraryNames='yyy',Folders='yyy',UserNames='yyy',RoleDefinitionNames='yyy'}
{LibraryNames='zzz',Folders='zzz',UserNames='zzz',RoleDefinitionNames='zzz'}
     "
/>

However, whenever I publish the project, the resulting App.config is transformed to this:

 <add key="rightsTable" value="&#xD;&#xA;{LibraryNames='xxx',Folders='xxx',UserNames='xxx',RoleDefinitionNames='xxx'}&#xD;&#xA;{LibraryNames='yyy',Folders='yyy',UserNames='yyy',RoleDefinitionNames='yyy'}&#xD;&#xA;{LibraryNames='zzz',Folders='zzz',UserNames='zzz',RoleDefinitionNames='zzz'}" />

Notice that the file, since it is an XML, encodes the break lines as &#xD;&#xA; and put all the string in one line.

I would like to know if there is a way I can publish the App.config without messing the line breaks.

Or, Is it possible to keep the string value in other file? so the App.config can read the value from the file without messing with the format


Solution

  • As @jwdonahue suggested, when having large text values which need multiple lines, is better to save it in an external file and then load it using the path of the file, which is saved in the config file. I set this as the answer in order to leave this question closed.