通过Bamboo根据环境动态更改.Net应用程序中的配置文件 [英] Dynamically change config files in .Net Application based on environments through Bamboo

查看:121
本文介绍了通过Bamboo根据环境动态更改.Net应用程序中的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用.net c#编写的Windows服务.我们有三种不同的环境,分别是devtestprod.我也有3个环境的3个不同的配置文件,例如devAppConfigTestAppConfigProdAppConfig.

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.

以前,我们曾经部署手册,所以我们用来替换配置文件并部署二进制文件.现在,对于使用Bamboo的部署,要实现自动化.

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.

现在我的问题是如何针对不同的环境部署动态更改AppConfig.

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

我在Bamboo命名DevDeployTestDeployProdDeploy中有3个不同的阶段.在运行这些阶段时,必须更改配置文件并进行部署,但是我不确定如何执行.

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?

推荐答案

我想这会起作用:

  1. 在解决方案的某些目录中以Config.ConfigurationName.xml格式创建少量配置文件,例如Config. DEV .xml,Config.测试 .xml. .
  2. 添加PreBuild事件(通过csproj属性窗口或在csproj文件中手动添加),例如:<PropertyGroup><PreBuildEvent>xcopy /y (ProjectDir)\Configs\Config.$(Configuration).xml $(ProjectDir)\CONFIG\Config.xml</PreBuildEvent></PropertyGroup> 或在VS rigth中单击项目->属性:
  3. 在VS中的Configuration Manager中为不同的配置添加一些配置,例如. DEV,测试. 我的项目配置:
  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:
  3. Add few configurations in VS in Configuration Manager for different configuration eg. DEV, Test. My project configuration:

  1. 在Bamboo msbuild中使用以下参数执行:/p:SolutionConfiguration=%CONFIGURATION%其中%CONFIGURATION%是Bamboo中的变量,其中说明了您要部署在哪个ENV上,例如 DEV,Test 等.
  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.

这篇关于通过Bamboo根据环境动态更改.Net应用程序中的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆