App.config 设置,环境变量作为部分路径 [英] App.config settings, environment variable as partial path
问题描述
我刚开始修改 app.config 和 xml,目前正在对一些我没有编写的代码进行重构.
目前我们有一个看起来像这样的片段:
I'm new to tinkering with app.config and xml, and am currently doing some refactoring in some code I haven't written.
Currently we have a snippet which looks like this:
<setting name="FirstSetting" serializeAs="String">
<value>Data Source=C:\Documents and Settings\All Users\ApplicationData\Company ...;Persist Security Info=False</value>
我想做的是让它指向类似 ${PROGRAMDATA}\Company\...
What I'd like to do is have it instead point to something like ${PROGRAMDATA}\Company\...
我怎样才能做到这一点,记住 PROGRAMDATA 并不总是指向 C:\ProgramData
?
How can I achieve this, keeping in mind that PROGRAMDATA will not always point to C:\ProgramData
?
推荐答案
我真的不想按照其他回复在代码中更改它,因为这消除了将其作为配置设置的目的.
I didn't really want to change it in code as per the other responses, since that removes the purpose of having it as a config setting.
事实证明,%ProgramData%\Company...
是在这种情况下使用环境变量的正确方法.
As it turns out, %ProgramData%\Company...
is the proper way of using environment variables in this context.
这篇关于App.config 设置,环境变量作为部分路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!