类库的配置文件在哪里物理位置? [英] Where are config files for class libraries physically located?

查看:140
本文介绍了类库的配置文件在哪里物理位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的猜测是,这个问题将属于"duh"类别,但尽管如此,我还是感到困惑.

My guess is that this question will fall under the category of "duh", but, nevertheless, I'm confused.

例如在Windows窗体应用程序中使用配置文件时,可以在 C:\ Program Files \ CompanyName \ ProductName \ Application.exe.config 中找到配置文件.但是,使用我正在开发的类库,从Visual Studio安装(与另一个项目一起)后,在安装文件夹中看不到" ClassLibrary.dll.config "文件.即使我在任何地方都看不到该文件,但从该文件中检索数据仍然可以正常工作.另外,从类库中的方法运行以下代码将返回您期望的路径: C:\ Program Files \ CompanyName \ ProductName \ ClassLibrary.dll.config .

When using config files in, for example, a Windows Forms Application, the config file can be found in C:\Program files\CompanyName\ProductName\Application.exe.config. However, with the class library I'm developing I do not see a "ClassLibrary.dll.config" file in the install folder after installing it (in tandem with another project) from Visual Studio. Even though I do not see the file anywhere, retrieving data from it works correctly. Plus, running the following code from a method within the class library returns the path you would expect: C:\Program files\CompanyName\ProductName\ClassLibrary.dll.config.

如果有人可以阐明我在这里所缺少的东西,那真是太棒了.

If someone could shed some light on what I'm missing here, that would be really awesome.

public static string MyMethod()
{
Assembly assem = Assembly.GetExecutingAssembly();
Configuration config = ConfigurationManager.OpenExeConfiguration(assem.Location);

return "The assembly location was: " + assem.Location + Environment.NewLine +
"The config file path was: " + config.FilePath;

// Gives me "C:\Program files\CompanyName\ProductName\ClassLibrary.dll.config"

}

推荐答案

在类库中,app.config文件几乎没有用.应用程序设置值存储在Settings.settings文件中,并编译到Settings.designer.cs文件中.

In a class library, the app.config file is pretty useless. Application setting values get stored in the Settings.settings file and are compiled into the Settings.designer.cs file.

如果直接在app.config中修改应用程序设置之一的值,则不会影响运行该应用程序时看到的设置值.您实际上必须打开设置"编辑器,这时它会注意到app.config文件和Settings.settings文件之间的区别,并询问您是否希望它使用来自app的值来更新Settings.settings文件.config.

If you modify the value of one of your application settings in app.config directly, that won't have an effect on the setting value seen while running the application. You have to actually open the Settings editor, at which point it will notice the difference between the app.config file and the Settings.settings file and inquire as to whether you'd like it to update your Settings.settings file using values from app.config.

这篇关于类库的配置文件在哪里物理位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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