2

I have a Settings files that is attached to app.config and I'm using pre-Build command line to call a bat file that supposes to override app.config based on the selected configuration for the project (Debug, release ...) before the build process. everything looks good, app.config is get updated on the build time (I can see the changes in settings and app.config). But when I'm trying to get any value in the settings using some command like this:

var test = Settings.Default.DBConn;

BUT... for the first time (that app.config is not get override) everything works fine, but when I'm changing the configuration (let's say from debug to release) an error is throwing that says something is wrong with the xml or something like that, the error is ConfigurationErrorsException, and the message is

The value of the property 'serializeAs' cannot be parsed. The error is: The enumeration value must be one of the following: String, Xml, Binary, ProviderSpecific.

Here is my bat file:

@echo off


if %1==Debug  GOTO DE
if %1==DEV GOTO DEV
if %1==Release GOTO PR



:DE
xcopy  %2configs\app_Debug.config  %2app.config  /Y
GOTO END

:PR
xcopy  %2configs\app_PROD.config  %2app.config  /Y
GOTO END

:DEV
xcopy  %2configs\app_DEV.config  %2app.config /Y
GOTO END

:END

I really don't know what is the problem I checked out these discussions

hanselman

Overriding App.Config settings

Manage multiple app config files during development

and few more. But I couldn't find any solution. Could you please help me on this! Thanks.

Community
  • 1
  • 1
Armen
  • 1,083
  • 2
  • 10
  • 18
  • 2
    This might help: http://mitasoft.wordpress.com/2011/09/28/multipleappconfig/ – Crono Apr 11 '14 at 18:35
  • @Crono, Thanks link was interesting, but doesn't help! :( – Armen Apr 11 '14 at 18:55
  • 1
    There's something wrong with the .bat file, I suppose. Nobody can see it, we can't even see the changed .config file. No point in keeping that a secret, you must document your question properly. – Hans Passant Apr 14 '14 at 17:57
  • Config files are exactly the same as the main app.config file just few values are changed. – Armen Apr 14 '14 at 18:01
  • When you run this pre-build does it break for all three variations(DE, PR, and DEV)? – Kixoka Apr 14 '14 at 18:12
  • Yes, basically every time that I'm overriding the app.config the error is happen, if I removed XCOPY command on DE label, means that there is no override anymore, it is working without any problem. so Something is happening when app.config is get override. – Armen Apr 14 '14 at 18:37
  • 1
    Could you switch to use config transforms instead of overwriting, using Slow Cheetah? http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5 – denvercoder9 Apr 16 '14 at 00:00
  • Are you sure the batch file is being called for each environment? I would have it write a small blank text file each time it's run, then run it with each config to ensure that it's being run. Or just add an echo at the end for "Operation Successful" and ensure it shows up in the build output for each config. If that's working, then we'd need to see some more context to help properly, I think. – Louis Ingenthron Apr 16 '14 at 15:45

1 Answers1

3

There is a Visual Studio extension called SloWCheetah which is designed for this purpose. It allows you to provided XSLT transforms to the app.config for each of your build configurations. Check it out http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

Mike Norgate
  • 2,393
  • 3
  • 24
  • 45
  • If you want to have the same result by doing it manually [you can do that.](http://vishaljoshi.blogspot.fr/2010/05/applying-xdt-magic-to-appconfig.html) It's quick and elegant :) – Gerard Walace Apr 21 '14 at 05:30