我们开发一个系统,其中客户端应用程序是 .NET 客户端,使用 Web 服务与服务器进行通信。我们需要能够使用不同的配置选项来部署客户端,例如IP地址等 到目前为止,我们基本上通过在 app.config 中注释/取消注释不同的配置来管理此问题,例如:
<!--<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>
但显然这不是问题的最佳解决方案,随着配置替代方案数量的增加,它变得有点难以管理。非常欢迎任何有关如何改进这一点的建议。
问候,奥拉
最佳答案
幸运的是,这个问题有一个很好的解决方案。下载并安装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 文件
这个解决方案确实工作得很好,有任何问题请回来
关于.net - 在 app.config 中管理多个客户端端点配置(IP 地址等)的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931359/