使用Properties.Settings.Default和设置备用配置文件? [英] Using Properties.Settings.Default and Setting Alternate Profiles?

查看:357
本文介绍了使用Properties.Settings.Default和设置备用配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候StackOverflow,

Greetings StackOverflow,

在过去的项目中,我已经习惯于使用Visual Studio中的设置设计器"来制作设置文件.在过去,这种方法效果很好.在我的最新项目中,我希望拥有同一个Settings类的多个版本(也称为配置文件),其中一个具有所有属性的生产/默认值,另一个具有测试值.

In past projects I've gotten used to using the Settings Designer in Visual Studio to make settings files. This has worked well in the past. In my latest project I have a desire to have multiple version, a.k.a. profiles, of the same Settings class, one with production/default values for all the properties and one with test values.

在搜索是否可行的同时,我注意到在Settings.settings文件的XML中,有许多提示可能具有多个设置配置文件.例如,在Settings.settings文件中,<SettingsFile>标记具有CurrentProfile属性,该属性始终设置为CurrentProfile="(Default)".在该标签内有一个名为<Profile />的空标签.最后,每个设置的<Value>标签都有一个Profile属性,该属性通常显示Profile="(Default)".

While in search to see if this is possible I noticed that in the XML for the Settings.settings file there are multiple hints that having multiple setting profiles might be possible. For instance in the Settings.settings file the <SettingsFile> tag has a CurrentProfile attribute which is always set to CurrentProfile="(Default)". Inside of that tag there is an empty tag called <Profile />. Lastly the <Value> tag for each setting has a Profile attribute that usually shows Profile="(Default)".

现在,我尝试查看<Profile />标记的全部含义,以及是否可以将其用于某些用途,但是我的搜索都没有涉及任何内容.

Now, I've tried looking to what the <Profile /> tag is all about and whether I can use it for something but none of my searches have come up with anything.

最终我想知道是否有一种方法可以使同一Settings类具有不同的配置文件,每个配置文件都有其自己的默认值,以便我可以使用它在我的代码中显示如下:

Ultimately I want to know whether there is a way to have different profiles of the same Settings class, each with it's own default values, so that I can use it might show up like this in my code:

Properties.Settings defaultSettings = Properties.Settings.Default;
Properties.Settings testSettings = Properties.Settings.Test;

如果任何人都知道在哪里可以找到设置文件的XML模式,或者我所要求的内容是否可能,请告诉我.

If anyone knows where to find the XML Schema for the settings file or if what I am asking for is possible please let me know.

推荐答案

我使用企业库,以针对不同的开发环境设置不同的配置.这需要一点时间来适应,但是有一个不错的配置工具可以读取配置文件并显示所有应用程序设置.您可以为计划使用的每个环境创建增量文件.我将 Merge Configuration 可执行文件添加到项目内的 lib 文件夹中,并通过添加一些Build Events在构建时进行合并来使它更上一层楼,以便文件可以自动用于部署:

I use the Enterprise library to set up different configurations with different development environments. It takes a little getting used to, but there's a nice configuration tool that'll read the config files and display all of your app settings. You can create delta files for each environment you plan on working with. I added the Merge Configuration executable into a lib folder within the project and topped it of by adding some Build Events to do the merging upon build so that the files are automatically ready for deployment:

"$(ProjectDir)lib\MergeConfiguration.exe" "$(ProjectDir)web.config" "$(ProjectDir)lib\Delta_Dev.dconfig" "$(ProjectDir)Configurations\web.config-dev.config"

这篇关于使用Properties.Settings.Default和设置备用配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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