为程序集创建一个app.config [英] Create an app.config for an Assembly

查看:118
本文介绍了为程序集创建一个app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于COM可见组件的.NET程序集,我想使用某些配置.我知道应用程序使用app.config,但是为我的程序集创建和使用app.config是否违反最佳实践?

I have a .NET assembly for a COM-visible component that I want to use some configurations. I know that applications use the app.config, but is it a violation of best practices to create and use an app.config for my assembly??

推荐答案

我的理解是,如果在生成程序集时拥有一个app.config文件,那么编译器会将其转换为assmeblyName.dll.config.如果此文件在运行时与汇编程序存在于同一目录中,则在您尝试读取app.config时都会将其加载. 这解释了它更加清晰了.

My understanding is that if when you build the assembly, you have an app.config file then it will be turned into assmeblyName.dll.config by the compiler. If this present in the same directory as the assmebly at runtime, then it will be loaded whenever you try and read app.config. This explains it a bit clearer.

我认为这是对配置数据进行分区的明智方法,以便与组装相关的数据始终保持组装状态.

I see it as being a sensible way of partitioning the configuration data so that the data relevant to the assembly is kept with the assmebly.

编辑:该技术适用于appSettings,不确定是否可以以相同方式共享app.config中的其他数据.

EDIT This technique applies to appSettings, not sure if other data in app.config can be shared in the same way.

这篇关于为程序集创建一个app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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