如何为我的本地机器设置不同的 web.config 设置? [英] How to have different web.config settings for my local machine?
问题描述
当我在本地运行时,我发现自己必须在 web.config 中手动更新我的 DefaultConnection 连接字符串.如何自动检测我何时在本地运行以及何时覆盖默认连接字符串?
I'm finding myself having to manually update my DefaultConnection connection string in my web.config when I run locally. How can I automatically detect when I'm running locally and - when I am - overwrite the default connection string?
我有调试/发布转换工作,但这些用于部署.我正在寻找一种方法来添加另一个选项 - 本地" - 如果有任何方法可以做到(或类似的方法).
I have debug/release transformations working, but these are for deployment. I'm looking for a way to add another option - "local" - if there's any way to do it (or something like it).
推荐答案
您需要添加解决方案配置才能添加 web.config 转换.
You need to add a solution configuration in order to add web.config transformations.
- 右键单击您的解决方案(在解决方案资源管理器中)
- 选择配置管理器"并在活动解决方案配置"下拉菜单,点击新建.
- 输入配置名称(例如本地")
- 从调试复制设置(似乎更适合开发)
- 选中创建新项目配置".
同时设置您的项目配置,完成后,右键单击 web.config,选择添加转换",您就可以开始了!
Set your projects configuration aswell, and when you're done, right click on the web.config, select "add transforms" and you're good to go !
然后,当您想使用本地连接字符串时,只需使用此配置而不是调试.
Then, when you want to use your local connection string, just use this configuration instead of debug.
这篇关于如何为我的本地机器设置不同的 web.config 设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!