我们开发了一个系统,其中客户端应用程序是使用 Web 服务与服务器通信的 .NET 客户端。我们需要能够使用不同的配置选项来部署客户端,例如 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>
Run Code Online (Sandbox Code Playgroud)
但很明显,这不是问题的最佳解决方案,随着配置备选方案数量的增加,它变得有点难以管理。任何如何改进这一点的建议都是最受欢迎的。
问候,奥拉
幸运的是,这个问题有一个很好的解决方案。下载并安装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 文件
该解决方案确实有效,如有任何问题请回来