在app.config中管理多个客户端端点配置(IP地址等)的最佳方法 [英] The best way to manage multiple client endpoint configurations (IP-address etc) in app.config
问题描述
我们开发的系统中,客户端应用程序是使用Web服务与服务器通信的.NET客户端.我们需要能够使用不同的配置选项来部署客户端,例如IP地址等到目前为止,我们已经通过基本上注释/取消注释app.config中的不同配置来解决此问题,例如:
We developing a system where the client application is a .NET client communicating with a server using web services. We need to be able to deploy the client with different configuration options, e.g. IP address etc. So far we have managed this by basically commenting/un-commenting different configurations in app.config, like:
<!--<client>
<endpoint address="https://localhost/services/service1"
binding="customBinding" bindingConfiguration="ServiceSoapBinding"
contract="ServiceReference.Service1" name="ServiceImplPort" />
<endpoint address="https://localhost/services/service2"
binding="customBinding" bindingConfiguration="ServiceSoapBinding"
contract="ServiceReference.Service2" name="ServiceImplPort" />
...
..
</client>-->
<client>
<endpoint address="https://prod.example.com/services/service1"
binding="customBinding" bindingConfiguration="ServiceSoapBinding"
contract="ServiceReference.Service1" name="ServiceImplPort" />
<endpoint address="https://prod.example.com/services/service2"
binding="customBinding" bindingConfiguration="ServiceSoapBinding"
contract="ServiceReference.Service2" name="ServiceImplPort" />
...
..
</client>
但是,显然这不是解决问题的最佳方法,随着配置替代方案数量的增加,它变得有些难以管理.欢迎提供任何改进建议.
But it seems obvious that this is not the best solution to the problem, it becomes a bit unmanageable as the number of configuration alternatives grow. Any suggestions how to improve this are most welcome.
关于,奥拉
推荐答案
幸运的是,这个问题有很好的解决方案.下载并安装 MSBuild.Community.Tasks
Fortunately there is a great solution to this problem. Download and install MSBuild.Community.Tasks
然后查看以下示例用法
http://chris.widdowson.id.au/?p=781
http://grahamrhay.wordpress.com/2012/03/16/multiple-config-transforms-at-build-time/
警告 设置时间超过5分钟,您将手动编辑.csproj文件
此解决方案效果很好,出现任何问题都会回来
This solution does work very well, come back with any issues
这篇关于在app.config中管理多个客户端端点配置(IP地址等)的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!