从插件模块读取 dll.config (不是 app.config!)
我正在编写一个 C# .NET 2.0 .dll,它是大型应用程序的插件。 我的模块的 Visual Studio 项目有一个 app.config 文件,该文件与 MyProj.dll 一起复制到 MyProj.dll.config 中。
计划是在部署 .dll 后编辑 MyProj.dll.config。 我正在尝试从修改后的本地文件中读取我的设置。 我尝试拉出 LocalFilesSettingsObject 并将其应用程序名称更改为我的 .dll,如下所示:
Properties.Settings config = Properties.Settings.Default;
SettingsContext context = config.Context;
SettingsPropertyCollection properties = config.Properties;
SettingsProviderCollection providers = config.Providers;
SettingsProvider configFile = Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
configFile.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name;
config.Initialize(context, properties, providers);
config.Reload();
这不起作用。 我正在努力解决整个 .NET 设置混乱的问题。 我想要一个食谱来完成这项任务。 我还想要一个关于设置如何在 .NET 2.0 中工作的清晰解释(带有示例)的链接
I am writing a C# .NET 2.0 .dll that is a plug in to a Larger application. The visual studio project for my module has a app.config file which is copied to a MyProj.dll.config along side of MyProj.dll.
The plan is that MyProj.dll.config will be edited after the .dll is deployed. I am trying to read my settings from that modified local file. I have tried pulling out the LocalFilesSettingsObject and changing it's application name to my .dll like this:
Properties.Settings config = Properties.Settings.Default;
SettingsContext context = config.Context;
SettingsPropertyCollection properties = config.Properties;
SettingsProviderCollection providers = config.Providers;
SettingsProvider configFile = Properties.Settings.Default.Providers["LocalFileSettingsProvider"];
configFile.ApplicationName = Assembly.GetExecutingAssembly().GetName().Name;
config.Initialize(context, properties, providers);
config.Reload();
That is not working. I am struggling to wrap my head around the whole .NET Settings mess. I'd like a recipe to finish this task. I would also like a link to a clear explanation (with examples) of how settings are supposed to work in .NET 2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要自己加载
x.dll.config
(使用配置API)。 所有自动文件处理(包括.Settings
)都是关于 machine.config/y.exe.config/user-settings 的。要打开命名的配置文件:
System.Configuration.dll
程序集。System.Configuration
创建如下代码:
You will need to load the
x.dll.config
(with the Configuration API) yourself. All the automatic file handling (including the.Settings
) is all about machine.config/y.exe.config/user-settings.To open a named config file:
System.Configuration.dll
assembly.System.Configuration
Create code like:
1- 在 Visual Studio 中打开 app.config 文件
2- 在“配置”标签中,在标签“appSettings”中添加您的配置,如下所示:
3- 在您的编写 c# 代码
,并且不要忘记
如果 System.Configuration 未显示,则必须在引用中添加引用“System.Configuration”
4-您可以按如下方式更新 dll 的配置:
1- open app.config file in visual studio
2- in the "configuration" tag add your configurations in tag "appSettings" as bellow:
3- in your code c#
and do not forgot to add this 2 usings for "ConfigurationManager" and for "Assembly"
if the System.Configuration does not show, you must add the reference "System.Configuration" in the References
4- you can update the configurations for the dll as bellow: