根据配置更新服务参考地址?
在调试过程中,我添加了一堆指向调试计算机上的服务的服务引用。有没有办法根据配置自动重新生成服务引用?当我准备好发布时,我真的不想将它们全部指向发布服务器,然后当我需要调试时返回并再次更改它们,等等。
基本上,我想要以下(完成)自动):
During debugging I added a bunch of service references pointing to services on the Debug machine. Is there any way to automatically regenerate the service references based upon the Configuration? I'd really rather not have to go through and point them all to the Release server when I'm ready to release, then when I need to debug go back and change them all again, etc.
Basicaly, I want the following (done automatically):
- Debug -> http://localhost/App/Service1.svc
- Release -> http://myserver/Service1.svc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法对配置进行条件编译。我在某些项目中使用的一件事是在代码中使用 #if 语句,用于更新配置中的服务引用。类似于下面的代码:
另一件我没有做过但我认为可能的事情是查看 msbuild 目标。 IIRC 您可以从 msbuild 执行任意命令,因此您可以根据构建配置使用自定义目标,并运行一些命令来根据该命令更新您的配置文件。
There's no way to do a conditional compilation for configuration. One thing I've used in some projects was to have #if statements in the code which updates the service reference from the config. Something similar to the code below:
Another thing, which I haven't done, but I think may be possible, is to look at the msbuild targets. IIRC you can execute arbitrary commands from msbuild, so you could use a custom target depending on the build configuration, and run some command which would update your config file based on that.
您可以使用 web.config 转换 无需代码即可解决此问题。
http://blogs .msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx
You can use web.config transformations to solve this without code.
http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx