XML File Replacement Program? (linked to web.config / WDP)

I ran into a lot of limitations with the web.config replacement code in my VS 2008 Web Deployment project. Here are some of them:

  • Sections cannot be replaced, only sections. Now if I only knew which sections were.
  • There seems to be some requirement behind the replacement. This is not just a "silly" text replacement. This makes it difficult to replace custom additions with web.config (it seems the files supporting the sections should be in the GAC or something similar).

So instead, think it would be easier to just write my own replacement program that is "dumb" but without these limitations. So before I hit the road, I wonder if there is something else that:

  • Works with XML files
  • For an INI file such as a list of keys / values
  • Can replace elements in the original XML file, with text content loaded from text files, specified by the values ​​in the INI file.

Or am I doing something completely wrong here? The WDP code replacement code just seems gimmicky (and hard to find documentation).

+2


source to share


2 answers


In my experience, I found it easier to have three files in my project, let's say Web-Release.config

, Web-Debug.config

and Web.config

then I change the project file (which is just the MSBuild script), to copy the contents of the file -Debug

or -Release

of Web.config

the build process. Fortunately, this type of behavior appears to be built into Visual Studio 2010, but it's pretty easy to add as of today just by right-clicking your project file, unloading it, and then editing the file to make switchcheroo:

<Target Name = "AfterBuild">
    <Copy SourceFiles = "Web-Debug.config" DestinationFiles = "Web.config" ContinueOnError = "false" Condition = "'$ (Configuration)' == 'Debug'" />
    <Copy SourceFiles = "Web-Release.config" DestinationFiles = "Web.config" ContinueOnError = "false" Condition = "'$ (Configuration)' == 'Release'" />
& lt / Target>

Another option that I have used in the past was to create an MSBuild task for this XML merge . This was useful for generating files App.config

that were split for the server that hosted the Windows console application (for debugging) and the Windows Service host (for production): most of the common options that were in App.config

the shared project folder, and each host project had App.config

which defined additional options, and then I edited each MSBuild of the host project to run my custom task to combine the two App.config

into one big one App.config

. But that was probably overkill.



I find it easier to just create a file .config

for each of your deployment scenarios as described above. If there is a lot in common, using the attribute configSource

on the elements can reduce duplication.

Hope this helps fix your problem, although this is probably not exactly what you were looking for.

+1


source


Disclaimer: I am about to spam you by talking about my program I wrote to do this

I wrote something for this: dashy . This is a little bit tweaking (it might depend on your environment), but it is designed to solve exactly the problem you are having - managing configurations for different environments (and also deploying them).



Alternatively, pre-dashy, I simply used nant tasks with specific .properties for each environment and did the appropriate post-build.

0


source







All Articles