我如何让我的c#控制台应用程序用app.config运行?

问题描述 投票:1回答:1

这对我来说很奇怪,虽然我确信我错过了一些简单而基本的东西。我有一个从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一行以一个未处理的异常Object reference not set to an instance of an object爆炸。同样,在开发环境中工作正常,只是在生产目录中不正常。

c# console-application app-config
1个回答
1
投票

这是因为app.config在编译时被重命名为YourAppName.exe.config。在你的 bindebug 文件夹或 binrelease 文件夹中查找。在那里你可以找到使用过的config-files

© www.soinside.com 2019 - 2024. All rights reserved.