相关疑难解决方法(0)

如何在.NET中为自定义配置节启用configSource属性?

根据此处发现的大量信息,我们如何才能使外部.config工作?我尝试了相同的设置,我将用于外部appSettings文件,但它无法找到我的自定义部分的文件.

<configSections>
...
    <section name="CustomSettings" type="Fully.Qualified.TypeName.CustomSettings, AssemblyName" />
</configSections>
<!-- this works -->
<CustomSettings attrib1="val1" attrib2="val2" .../>
Run Code Online (Sandbox Code Playgroud)

然而...

<!--this does not work-->
<CustomSettings configSource="someExternalFile.config"/>
Run Code Online (Sandbox Code Playgroud)

someExternalFile.config包含的位置

<CustomSettings attrib1="val1" attrib2="val2" .../>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

.net c# configuration app-config configuration-files

27
推荐指数
1
解决办法
2万
查看次数

<appSettings />是否可以包含设置并引用另一个文件中的另一个<appSettings />部分?

我可以<appSettings />在app.config中有一个包含许多设置的<appSettings />部分,但是它也引用了不同文件中的部分吗?

这将允许我保留只有开发人员应该感兴趣的配置选项,例如在主窗口上显示调试输出的选项(非常混乱但对我有用)或将某些文件保存到特定位置.

具体来说,这就是我想要实现的目标:

<!-- this is the appSettings section of the normal app.config file,
     which also contains everything else that app.config would -->
<appSettings configSource="AppSettings.config"> <!-- references another file -->
  <add key="deployment_config_option1" value="1"/>
  <add key="deployment_config_option2" value="2"/>
</appSettings>

<!-- this a new appSettings section of another file called DevSettings.Config
     which only contains settings us developers are interested in
     by keeping these settings in a different file, 
     I can ensure it's never deployed -->
<appSettings> <!-- …
Run Code Online (Sandbox Code Playgroud)

.net app-config visual-studio-2010

10
推荐指数
1
解决办法
2929
查看次数