类库可以有 App.config 文件吗? [英] Can a class library have an App.config file?
问题描述
这是我目前的解决方案:
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.
这可能吗?有什么建议吗?
Is this possible? Any recommendations?
部署时,输出会不会把这些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屋!