Jason Capriotti
Jason Capriotti

Reputation: 2060

Web Deploy Package - setParameter for web.config with complex XML

I've been making some headway using Web Deploy packages that transform web.config files on deploy rather than build. The goal in this is "build once, deploy everywhere". The problem I'm having is when I need to add or change complex XML in a web.config.

For example, if my base web.config contains this:

<customSection>
</customSection>

I might want to the deployed web.config to look like this:

<customSection>
    <someSettingKey>QA Setting</someSettingKey>
</customSection>

It seems to work to have my SetParameters.xml look something like:

<setParameter name="customSection" value="&lt;someSettingKey&gt;QA Setting&lt;/someSettingKey&gt;" />

But that seems a bit cumbersome, especially when the XML gets more nested / complex.

Are there better ways of doing this?

Upvotes: 2

Views: 433

Answers (1)

Jason Capriotti
Jason Capriotti

Reputation: 2060

I was able to break up the configuration a bit so that the base web.config (for local testing) has the simple XML, and have one transform for the Release configuration (i.e. what runs on the servers). This transform adds the complex XML, and only a few keys within it need to change via the SetParameters.xml for QA, Production, etc.

The complexity in the XML came from encrypting a web.config section. The encryption (and thus, complexity) is only needed on the server.

I suppose another way to do it might be breaking up the config files using the configSource attribute for certain sections... however I didn't really flesh that out.

Upvotes: 1

Related Questions