什么时候应该使用.resx文件,什么时候去.config文件?
两者在使用方面的基本区别是什么?
我看到有关.NET中自定义配置的简单示例.我的情况有点复杂,有嵌套节点.
我希望能够从配置文件中读取这个:
<environments>
<environment name="live" url="http://www.live.com">
<server name="a" IP="192.168.1.10"></server>
<server name="b" IP="192.168.1.20"></server>
<server name="c" IP="192.168.1.30"></server>
</environment>
<environment name="dev" url="http://www.dev.com">
<server name="a" IP="192.168.1.10"></server>
<server name="c" IP="192.168.1.30"></server>
</environment>
<environment name="test" url="http://www.test.com">
<server name="b" IP="192.168.1.20"></server>
<server name="d" IP="192.168.1.40"></server>
</environment></environments>
Run Code Online (Sandbox Code Playgroud)
如果有人能提供一些代码,我会很感激.
谢谢!
我想使用配置文件和一些简单的数学表达式,如添加或减少.
例如:
[section]
a = 10
b = 15
c = a-5
d = b+c
Run Code Online (Sandbox Code Playgroud)
有没有办法使用ConfigParser模块?我发现了一些在配置文件中使用字符串作为变量的例子,但如果我使用它,我会得到一个未计算的字符串(我必须在我的python代码中解析它).
如果在ConfigParser中不可能,您推荐使用任何模块吗?
现在,application.ini位于我项目的以下文件夹中:
projectfolder/application/configs/application.ini
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我必须将其移至
projectfolder/application.ini
Run Code Online (Sandbox Code Playgroud)
可能吗?
谢谢
我正在尝试读取这样的配置文件:
var dllPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.
GetExecutingAssembly().GetName().CodeBase);
dllPath = dllPath.Replace("file:\\", string.Empty);
var configPath = string.Format(@"{0}\..\contentFolders.config", dllPath);
var fileMap = new ExeConfigurationFileMap() {ExeConfigFilename = configPath};
var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap,
ConfigurationUserLevel.None);
var contentFolderConfig =
(ContentFolderSettings)config.GetSection("contentFolderConfiguration");
Run Code Online (Sandbox Code Playgroud)
我ContentFolderSettings在Corp.Common项目中定义了它继承自ConfigurationSection.这是以下内容contentFolders.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<section name="contentFolderConfiguration"
type="Corp.Common.ContentFolderSettings, Corp.Common"
requirePermission="false"/>
<contentFolderConfiguration>
<contentFolders>
<contentFolder key="ImagesFolder" path="content\images"/>
<contentFolder key="CssFolder" path="content\css"/>
...
</contentFolders>
</contentFolderConfiguration>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但线路呼叫config.GetSection()正在投入InvalidCastException:
Unable to cast object of type 'System.Configuration.DefaultSection' to type
'Corp.Common.ContentFolderSettings'.
Run Code Online (Sandbox Code Playgroud) 试图永久地使用UTF8并且无法让MAMP安装MySQL来识别my.cnf值.
MAMP版本2.0.5(2.0.5)
MySQL 5.5.9
my.cnf文件:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-collation=utf8_general_ci
collation_server=utf8_general_ci
character_set_server=utf8
init-connect='SET NAMES utf8'
Run Code Online (Sandbox Code Playgroud)
文件位置:
/应用/甲基苯丙胺/库/ conf目录/
启动时MySQL变量:
mysql> show variables where variable_name LIKE '%char%' OR variable_name LIKE '%colla%';
+--------------------------+--------------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /Applications/MAMP/Library/share/charsets/ |
| …Run Code Online (Sandbox Code Playgroud) 这类似于在Python中放置配置文件的位置?,但我要问的是在Windows系统上用py2exe或类似程序编译/冻结的脚本.(即,这一个:用于任意字节的用户友好字符串的配置文件格式是什么? https://gist.github.com/1119561)
我的第一个想法是将配置文件放在与.exe相同的文件夹中,这使它有点自包含.但是,如果我将文件与.exe关联,它将从他们的目录调用,而不是它自己的,所以我需要像我如何在Python中获取当前执行文件的路径?找到配置文件.
这是最好的方法吗?或者是否有一些标准配置文件位置可供搜索,例如/sf/answers/529756251/?
Boost属性树看起来像是一个用于解析配置文件的优秀库.但是,我无法弄清楚如何处理每个键有多个值的情况.例如,假设我正在指定一个这样的框:
box
{
x -1 1
y -1 1
z -1 1
}
Run Code Online (Sandbox Code Playgroud)
其中x,y和z是框的边界上x,y和z轴分别使用property_tree的INFO格式指定.我在手册中提到使用带有空格的值的引号,但后来我没有看到我可以将这些值作为数字导入.我必须将字符串解析为数字,这似乎首先打败了使用property_tree的目的.我当然可以给每个数字一个关键:
box
{
xlo -1
xhi 1
ylo -1
yhi 1
zlo -1
zhi 1
}
Run Code Online (Sandbox Code Playgroud)
但这似乎很麻烦,并会膨胀我的配置文件.我还注意到我可以在program_options中处理这种情况,但是我失去了嵌套的配置文件功能(是的,我知道我可以使用点符号来"嵌套",但它不一样).
有没有办法导入例如x作为这样的数字列表?
c#中是否有lib可以读取和写入配置或某种配置文件?
我不是在谈论app.config,而是更像是类似于ol .ini文件的custom.config,其中内置了lib /函数来读取/写入配置文件.
我当然可以写自己的,但想知道是否存在一些常见的lib或方法来做到这一点......
我知道自定义配置部分,但不想采取这种方式.
解
我找到了我要找的东西.这将有效:
http://www.codeproject.com/Articles/14465/Specify-a-Configuration-File-at-Runtime-for-aC-Co
在跨平台应用程序中,我正在使用一个配置文件,允许用户根据需要覆盖各种默认值.
我遇到的问题是......在哪里放置/寻找这个配置文件,特别是关于MacOS X(我从未使用过,无法访问)?我知道MacOS X是基于Unix的,但是我也知道很多东西都是以非常不同的方式完成的......
我目前的选择:
Unix的:
~/.config/<appname>/<appname>.cfg
Run Code Online (Sandbox Code Playgroud)
Windows(这个也不确定,这里的东西似乎到处都是 - %LOCALAPPDATA%或%USERPROFILE%似乎也是有效的选择):
%APPDATA%/<appname>/<appname>.cfg
Run Code Online (Sandbox Code Playgroud)
苹果系统:
...?
Run Code Online (Sandbox Code Playgroud)
有关MacOS或其他选择的任何评论吗?