取决于配置模式的不同应用程序设置 [英] Different application settings depending on configuration mode

查看:92
本文介绍了取决于配置模式的不同应用程序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我可以在.Net应用程序中设置应用程序(或用户)级别设置的方式吗,该设置取决于应用程序当前的开发模式? IE:调试/发布

Is anyone aware of a way that I can set application (or user) level settings in a .Net application that are conditional on the applications current development mode? IE: Debug/Release

更具体地说,我在应用程序设置中有一个指向我的Web服务的url引用。在发布模式下,我希望这些设置在调试模式下指向 http://myWebservice.MyURL.com 喜欢那些设置为 http://myDebuggableWebService.MyURL.com

To be more specific, I have a url reference to my webservices held in my application settings. During release mode I would like those settings to point to http://myWebservice.MyURL.com during debug mode I would love those settings to be http://myDebuggableWebService.MyURL.com.

有什么想法吗?

推荐答案

我知道这是几年前提出的,但以防万一有人在寻找我使用的简单有效的解决方案。

I know this was asked years ago, but just in case anyone is looking for a simple and effective solution that I use.


  1. 转到项目属性的设置选项卡(您将在此处看到您的Web服务URL或任何其他设置)。

  1. Go to project properties, Settings tab (you'll see your web service URL or any other settings already listed here).

单击设置页面上可用的查看代码按钮。

Click the "View Code" button available on the Settings page.

类型

this.SettingsLoaded += Settings_SettingsLoaded;


  • 在构造函数下添加以下函数:

  • Add the following function under the constructor:

    void Settings_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e)
    {
        #if(DEBUG)
        this["YOUR_SETTING_NAME"] = VALUE_FOR_DEBUG_CONFIGURATION;
        #else
        this["YOUR_SETTING_NAME"] = VALUE_FOR_RELEASE_CONFIGURATION;
        #endif
    }
    


  • 现在,无论何时运行项目,它都只会编译与当前构建配置匹配的行。

    Now whenever you run your project, it will compile only the line that matches the current build configuration.

    这篇关于取决于配置模式的不同应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆