0

I have 3 config files in my windows service c# application naming dev.config, QA.config and prod.config.
I have added 3 new Configuration Managers dev, QA and Prod and also added a prebuild event in the project properties which copies the appropriate appropriate config file into AppConfig before building the application.

xcopy /y "$(ProjectDir)ConfigFiles\$(Configuration).config" "$(ProjectDir)App.config" 

Now with this method , I need to build the code everytime I need to deploy in each environment.

Command used to build code each time:

msbuild.exe solutionname.sln /t:Rebuild /p:Configuration=Dev
msbuild.exe solutionname.sln /t:Rebuild /p:Configuration=QA
msbuild.exe solutionname.sln /t:Rebuild /p:Configuration=Prod

Is there any way I can use the same binaries to deploy into all the environments without having to build it everytime.Something like set environment variables in each machine and use them to determine which environment we are in and automatically use the appropriate config file through code.

Any help on this is highly appreciated.

CrazyCoder
  • 2,194
  • 10
  • 44
  • 91
  • *have added 3 new Configuration Managers dev, QA and Prod* this one is `app.config`? is `app.config` stored on the compiled binaries..? i never thought you need to rebuild whenever a config changes.. though you can try to [get the environment variables](https://stackoverflow.com/a/185214/4648586).. – Bagus Tesa Oct 24 '18 at 09:15
  • @BagusTesa, What I meant is by default the app.config has the dev app settings in it, which I cant deploy in QA environment. If I have to deploy in QA environment, I need to build the code again, which copies QA.config file into app.config file and creates binaries, using prebuild event. – CrazyCoder Oct 24 '18 at 09:18
  • MSBuild is a pretty lousy deployment tool. There is lots of tooling around to assist devops in automating the deployment of an app, beyond a simple .bat file that xcopies a file. You have to be specific to get decent advice, do so at a site like https://devops.stackexchange.com/ – Hans Passant Oct 24 '18 at 10:44

0 Answers0