【问题标题】:How do I get my c# console application to run with an app.config?如何让我的 c# 控制台应用程序与 app.config 一起运行?
【发布时间】:2020-09-21 03:38:08
【问题描述】:

这对我来说很奇怪,尽管我确信我缺少一些简单和基本的东西。我有一个从 app.config 读取 SQL 连接的控制台应用程序。它在 Visual Studio 中运行良好。当我将三个项目移动到一个目录进行测试时,.exe、app.config 和它需要运行的水晶报告,它不会从 app.config 中读取。

Console.WriteLine("about to get connection string...");
var connectionString = ConfigurationManager.ConnectionStrings["InformConnectionString"].ConnectionString;

它在 var connectionString 行上爆炸,带有未处理的异常对象引用未设置为对象的实例。同样,在开发环境中工作正常,只是在生产目录中不行。

【问题讨论】:

  • 可能你遗漏了一些 dll 文件

标签: c# console-application app-config


【解决方案1】:

这是因为 app.config 在编译时被重命名为 YourAppName.exe.config。查看您的 bin/debug 文件夹或 bin/release 文件夹。在那里你可以找到使用的配置文件

【讨论】:

  • 完美。我什至没有看到其他 app.config。
猜你喜欢
  • 2015-02-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
  • 2012-04-21
  • 2022-11-11
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
相关资源
最近更新 更多