-2

我已经制作了 c# 控制台应用程序的 exe。我想传递 app.config 文件作为参数来运行该 exe。当我传递与 exe 同名的配置文件时,它工作正常。但是,如果我更改该配置文件的名称或路径,它就会开始给出错误

你调用的对象是空的

你能帮我解决这个问题吗?也让我知道我们是否可以一次将多个配置文件传递给同一个 exe。

谢谢,曼达尔

4

1 回答 1

1

By default ConfigurationManager class work with current application's default configuration. You can change the file name however you have to use appropriate method e.g. OpenExeConfiguration.

There are many ways you can achieve this in C# console application.

One is explained here...

http://msdn.microsoft.com/en-us/library/ms224437.aspx

Yes you can accept n number of arguments from command line and you can use them as file name to be read.

Remember configuration file is just like any other file (in XML format), as long as you have a valid file name and path you can read its content one or the other way.

If this does not help post your code; how you are loading and reading the configuration file.

于 2013-05-16T05:24:02.273 回答