简体   繁体   English

如何与app.config一起使用

[英]how to use with app.config

this is my app config: 这是我的应用程序配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="version" value="1.0.0."/> 
  </appSettings>
</configuration>

this is my code 这是我的代码

txtVersion.Text = ConfigurationSettings.AppSettings["version"];

I get null value 我得到空值

尝试使用ConfigurationManager类:

txtVersion.Text = ConfigurationManager.AppSettings["version"];

There is nothing wrong with your code, although ConfigurationManager now replaces ConfigurationSettings . 尽管ConfigurationManager现在替换了ConfigurationSettings ,但是您的代码没有错。

If you are running in Visual Studio, make sure your app.config has been copied to the bin\\debug (or bin\\release depending on if you are in release or debug mode) and has been correctly renamed to [yourappname].exe.config. 如果您在Visual Studio中运行,请确保已将app.config复制到bin \\ debug(或bin \\ release,具体取决于您是否处于发行或调试模式),并已正确重命名为[yourappname] .exe。配置。

Make sure you have added the app.config to your project within Visual Studio (rather than just creating the file in the dir). 确保已将app.config添加到Visual Studio中的项目中(而不是仅在目录中创建文件)。 Alternatively, put the file manually in the bin\\debug dir with the correct name as above and try again. 或者,使用上述正确的名称将文件手动放入bin \\ debug目录中,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM