DCSIMG
Managing Multiple Configuration File Environments with Pre-Build Events - Zuker On Foundations

Zuker On Foundations

The realm of .NET (WPF, WCF and all around)
Managing Multiple Configuration File Environments with Pre-Build Events

Almost every project I write has a configuration file and its content varies from one environment to another.
In this case, managing multiple configuration files can make life a lot easier.

There are different approaches for doing this, I'll link to a demonstration made by Scott Hanselman a while back - Click Here.

In short:
1 - Create configuration builds.
2 - Add a batch file at the root of the project as written below.
3 - Add a Pre-Build action to execute it.

The batch file 'copyifnewer.bat' content:
@echo off
echo Comparing two files: %1 with %2

if not exist %1 goto File1NotFound
if not exist %2 goto File2NotFound

fc %1 %2
if %ERRORLEVEL%==0 GOTO NoCopy

echo Files are not the same.  Copying %1 over %2
copy %1 %2 /y & goto END

:NoCopy
echo Files are the same.  Did nothing
goto END

:File1NotFound
echo %1 not found.
goto END

:File2NotFound
copy %1 %2 /y
goto END

:END
echo Done.

The pre-build action to be inserted:
"$(ProjectDir)copyifnewer.bat" "$(ProjectDir)web.config.$(ConfigurationName)" "$(ProjectDir)web.config"

 

Published Thursday, January 15, 2009 3:24 PM by Amir Zuker

תגים:,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: