Click here to Skip to main content
15,886,002 members
Articles / Mobile Apps / Windows Mobile

Config Customization at Build Time in Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.93/5 (12 votes)
22 Jun 2008CPOL5 min read 68.4K   326   39  
Modify config files with machine- or build-specific differences at compile time.
ECHO OFF
:: ConfigMerge.bat 
:: by Jim Rogers
:: Published on CodeProject.com
:: http://www.jimandkatrin.com/codeblog/2008/06/config-merge.html

:: Tildes strip the quotes off the parameters
SET _path=%~1
SET _config=%_path%%~2
SET _target=%_path%%~3

:: First file to do a diff against, if it exists
SET _diff=%_path%%~4

IF NOT EXIST "%_config%" GOTO NOCONFIG

IF EXIST "%_diff%" GOTO DOMERGE

:: Optional second file to do a diff against, if it exists
IF NOT [%~5]==[] (
	SET _diff=%_path%%~5
	IF EXIST "%_diff%" GOTO DOMERGE
)

ECHO Config file not modified

IF NOT "%_config%"=="%_target%" (
	ECHO Copying config file to target
	COPY "%_config%" "%_target%"
)

GOTO END

:DOMERGE
:: Modify the config with the difference file
"%_path%..\ConfigMerge.exe" "%_config%" "%_diff%" "%_target%"
:: If ConfigMerge.exe reports an exception, pass this up to visual studio
IF ERRORLEVEL 1 EXIT 1
GOTO END

:NOCONFIG
:: Config file was not found - probably problem setting up the prebuild
ECHO Config file %_configFile% not found

:END
EXIT 0

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Jim is a developer working in Auburn, Alabama, USA. He started working as a programmer in 1997; much of his early experience was with MFC and ASP, with brief forays into Java servlets, Borland's OWL, and plain-old windows API.

Since 2001 Jim has worked primarily with .NET, writing windows and web applications, windows services, and client-server apps. With a little bit of AS3/Flex code thrown in there.

Jim comments code in the first person (much to the amusement of his coworkers,) and feels especially weird writing about himself in the third.

Comments and Discussions