0

I have a windows service written in .net c#. We have three different environments say dev, test and prod. I also have 3 different config files for 3 environments say devAppConfig , TestAppConfig and ProdAppConfig.

Earlier, we used to deploy manual, so we used to replace the config files and deploy the binaries.Now the deployments are to be automated for that we are using Bamboo.

Now my question is how do I dynamically change the AppConfig for different environment deployments.

I have 3 different stages in Bamboo naming DevDeploy , TestDeploy, ProdDeploy. When I run these stages, it has to change the config file and do the deployment, but I'm not sure how.

Can anyone guide me in the right direction for my issue?

enter image description here

CrazyCoder
  • 2,194
  • 10
  • 44
  • 91
  • @PranavSingh This is not duplicate as I want these changes to be done in Bamboo. And in the link provided by you, there is no mention of bamboo anywhere – CrazyCoder Sep 10 '18 at 08:51
  • 1
    I hope if you have multiple environments, then you will create multiple deployment projects too. So for each deployment projects, you can write a powershell script or node script to choose the config file and deploy using it. – Chidambaram Sep 11 '18 at 13:58
  • @Chidambaram I have only build project and not deployment project. Since it is copying of binaries, I'm using powershell scripts to copy the binaries from Bamboo agent to destination server. Do you think I should take deployment project instead of build project? – CrazyCoder Oct 11 '18 at 08:55

1 Answers1

0

I suppose this would work:

  1. Create few configuration files in some directory in the solution in the format Config.ConfigurationName.xml, eg Config.DEV.xml, Config.Test.xml...
  2. Add PreBuild event (by the csproj properties window or manually in the csproj file), for example: <PropertyGroup><PreBuildEvent>xcopy /y (ProjectDir)\Configs\Config.$(Configuration).xml $(ProjectDir)\CONFIG\Config.xml</PreBuildEvent></PropertyGroup> or in VS rigth click on the project -> Properties: enter image description here
  3. Add few configurations in VS in Configuration Manager for different configuration eg. DEV, Test. My project configuration:

My project configuration

  1. Execute in the Bamboo msbuild with arguments: /p:SolutionConfiguration=%CONFIGURATION% where %CONFIGURATION% is a variable in Bamboo saying on which ENV you are deploying, eg DEV, Test etc.
  • Hey sorry for the late reply. I was trying this approach. I'm getting this error when I added the prebuildevent as mentioned in the second point. And also the project is not loading in VS. Error : The element <#text> beneath element is unrecognized. – CrazyCoder Oct 11 '18 at 08:46
  • I have added the image in my question for the same – CrazyCoder Oct 11 '18 at 08:49
  • Sorry, I skipped the place where this PreBuildEvent node should be placed. It should be a new PropertyGroup: ... but I think the best option is to do this by the VS. I will add a screen in a moment – Adrian Stanisławski Oct 11 '18 at 08:57
  • Thanks a lot for the help – CrazyCoder Oct 11 '18 at 10:17