9

Using web.config transforms, I want to make sure and include a comment at top of the resulting web.config to indicate which transform file(configuration) was used to generate it.

I don't see a way to include comments from the transform files, can this be done?

EDIT:

It appears that all comments in the transform files are stripped.

BoxOfNotGoodery
  • 1,001
  • 1
  • 7
  • 24

1 Answers1

5

The following does not directly answer how to add or preserve comments, but it might get you toward the goal of knowing which transform was used. Admittedly, it feels a little strange, so keep your eyes open for other answers. It's just the first thing that came to mind.

I don't know of a way to preserve the comments from transforms, but you could always insert a dummy application setting to deliver the information. The app doesn't actually have to use it for anything =p

Here I have it being inserted by the transform, assuming it isn't in the main web.config. You could just as easily do a Replace.

<appSettings>
    <add key="WhichTransformWasUsed" value="Production" xdt:Transform="Insert"/>
</appSettings>
David Ruttka
  • 14,269
  • 2
  • 44
  • 39
  • As discussed in [this answer](http://stackoverflow.com/a/22812595/3507333), adding comments only works by adding or replacing a parent element. However, your solution works great since all I wanted was a quick sanity check at the top of my config file! – madannes Jan 04 '17 at 16:05
  • I'm also using visually-distinctive format that stands out among the other entries, specifically: `` That makes it very easy to notice in the resulting/transformed .config file – taiji123 May 04 '18 at 19:52