简体   繁体   English

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

[英]How do I get my c# console application to run with an app.config?

This is peculiar to me although I'm sure I'm missing something simple and basic.这对我来说很特殊,尽管我确信我缺少一些简单而基本的东西。 I have a console application that reads a SQL connection from an app.config.我有一个控制台应用程序,它从 app.config 读取 SQL 连接。 It works fine in Visual Studio.它在 Visual Studio 中运行良好。 When I move three items to a directory to test, the.exe, the app.config, and the crystal report that it needs to function, it won't read from the app.config.当我将三个项目移动到一个目录进行测试时,.exe、app.config和它需要的水晶报告到function,它不会从app.config中读取。

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

It bombs on the var connectionString line with an unhandled exception Object reference not set to an instance of an object.它轰炸了 var connectionString 行,出现未处理的异常 Object 引用未设置为 object 的实例。 Again, works fine in the development environment, just not in the production directory.同样,在开发环境中工作正常,只是在生产目录中不行。

It is because the app.config is renamed to YourAppName.exe.config when it is compiled.这是因为 app.config 在编译时被重命名为 YourAppName.exe.config。 Look in your bin/debug folder or bin/release folder.查看您的 bin/debug 文件夹或 bin/release 文件夹。 There you find the used config-files在那里你可以找到使用的配置文件

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

相关问题 如何在VS2010 C#控制台应用程序中将我的App.config编译到我的exe中? - How do I compile my App.config into my exe in a VS2010 C# console app? 在 C# 控制台应用程序 app.config 中嵌入 webclient 的凭据? - Embed credentials for webclient in C# Console Application app.config? 控制台应用程序中的 App.Config 文件 C# - App.Config file in console application C# 在c#控制台应用程序中,app.config的替代方案是什么? - What is the alternate to app.config in c# console application? 如何让我的应用程序在两个app.config文件之间进行选择? - How do I get my application to choose between two app.config files? 如何获得 c# 单元测试以使用 App.Config? - How do I get a c# Unit Test to use App.Config? 如何在 C# 控制台应用程序中动态加载外部 App.Config? - How to load external App.Config dynamically in C# Console application? 如何将 app.config 文件添加到项目(控制台应用程序 C#) - How to add an app.config file to a project (Console Application C#) C#VS2013发布后如何在控制台应用程序中使用App.config - C# VS2013 How to use App.config in a console application after publish it 如何使用app.config使控制台应用程序传输大于4 MB的文件 - How can I make my console application transfer files bigger than 4 MB using app.config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM