一个类库可以有一个App.config文件? [英] Can a class library have an App.config file?

查看:159
本文介绍了一个类库可以有一个App.config文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的解决方案是在此刻看起来像:

Here is what my solution is looking like at the moment:

在Tutomentor.Branding项目,我想保存在App.config文件品牌信息,如姓名,颜色等。

In the Tutomentor.Branding project, I'd like to save branding information in the App.config file, like names, colors, etc.

在Tutomentor.Data项目中,App.config的是,当我添加了一个实体的.edmx模型文件创建的。

In the Tutomentor.Data project, the App.config was created when I added an entity .edmx model file.

这可能吗?任何建议?

当部署,将输出组合这些的App.config文件到一个单一的?

When deploying, will the output COMBINE these App.config files into a single one?

推荐答案

没有,类库可以保存设置文件,但它们的值会在应用配置中定义(web.config中的app.config ...)。

No, class libraries can hold setting files, but their values will be defined in the application configuration (web.config, app.config...).

这是因为配置设置覆盖功能。

That's because of configuration settings overriding feature.

您需要在您的应用程序(WPF,SL,ASP.NET ...)的的app.config或web.config文件来声明组件配置部分和定义设置特定数量的定义值正确装配设置。

You'll need to declare the assemblies' configuration sections in the app.config or web.config of your application (WPF, SL, ASP.NET...) and define a value for a particular number of settings defined in the proper assembly settings.

编辑:
设置文件添加到您的项目,并添加与应用范围的设置,你的大会将有这样的事情:

Add a setting file to your project and add a setting with application scope, and your assembly would have something like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Assembly1.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <Assembly1.Settings1>
            <setting name="settingA" serializeAs="String">
                <value>a value</value>
            </setting>
        </Assembly1.Settings1>
    </applicationSettings>
</configuration> 

现在你需要去您的应用程序,你需要复制粘贴段组,段声明,并为设置的值的定义。就这样。

Now you'd need to go to your application, and you need to copy-paste the section group, and section declarations, and the definition of the values for the settings. That's all.

这篇关于一个类库可以有一个App.config文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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