从app.config文件读取值时出现问题 [英] Problems while reading value from app.config file
问题描述
我正在用C#制作一个Windows应用程序,在其中我添加了一个文件作为app.config文件.我已经在该文件中编写了一些代码,
I am making one windows application in c# in where i added one file as app.config file.I have written some code in that file as
<appSettings>
<add key ="FlagForArchiving" value="true"/>
</appSettings>
在"program.cs"文件中,我将此值读取为
In 'program.cs' file i am reading this value as
ConfigurationSettings.AppSettings["FlagForArchiving"].ToString();
在本地计算机上,我可以从配置文件中检索值,但是每当我构建该应用程序并在其他任何计算机上运行时,我都无法从配置文件中读取该值.我正在尝试在Windows 7上运行我的应用程序.请帮助我.谢谢.
On local machine i can retrieve value from config file but whenever i am building that application and running on any other machine then I cant read the value from config file.I am trying to run my application on windows 7.Please help me.Thanks in advance.
推荐答案
app.config
在构建时重命名为<MyProgramName>.exe.config
.程序运行时,它将查找该<MyProgramName>.exe.config
文件,而不是app.config
.
app.config
is renamed to <MyProgramName>.exe.config
when you build. When your program runs it will look for that <MyProgramName>.exe.config
file, not app.config
.
您需要将重命名的文件(<MyProgramName>.exe.config
)与程序一起部署.
You need to deploy the renamed file (<MyProgramName>.exe.config
) along with your program.
根据您的情况,您需要复制OBViewer.exe
,OBViewer.exe.config
和OBViewer.exe
所依赖的任何其他文件(例如,调试/发布目录中的其他.dll程序集).
In your case, you need to copy over OBViewer.exe
, OBViewer.exe.config
, and any other files that OBViewer.exe
depends on (e.g. other .dll assemblies in your debug/release directory).
顺便说一下,这个重命名的文件通常被称为"app.config",即使它没有相同的文件名.
By the way, this renamed file is often commonly referred to as "app.config", even if it doesn't have the same filename.
这篇关于从app.config文件读取值时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!