我有一个app.config文件,其中包含以下内容
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name ="PowershellSnapIns" type ="System.Configuration.DictionarySectionHandler,System"/>
</configSections>
<PowershellSnapIns>
<add key="SnapIn1" value="WebAdministration" />
<add key="SnapIn2" value="Jimmy Hendrix" />
<add key="SnapIn3" value="..." />
</PowershellSnapIns>
</configuration>我本来打算使用ConfigurationSettings类来读取它,但是已经被弃用了。这是相当简单的使用。现在我必须使用ConfigurationManager类,并且我现在可以使用下面的代码来读取它。
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
IDictionary SnapInList = (IDictionary) config.GetSection("PowershellSnapIns");但它一直在出错。我更改了app.config属性以复制到构建中,但它始终接受找不到该文件的事实。异常表明它正在寻找TestConsole.vshost.exe.config。vs2k8sp1现在会自动为您重命名app.config吗?如果是,我做错了什么?当然,我不需要将app.config文件重命名为debug vhost。我知道在发行版中,它可能会被重命名为TestConsole.exe.config。那么到底出了什么问题呢?这是代码错误的情况还是什么?
发布于 2009-08-14 16:15:42
下面是我是如何做到的:
确保System和System.Configuration.dll在-Make目录中可用。为此,您可以添加对这两个dll的引用,并将它们的copy local属性设置为true。
-Make确保在App.Config文件中,将copy local属性设置为false。
-Use以下方法:
public static string XMLCheck
{
get
{
var section =(Hashtable)ConfigurationManager.GetSection("PowershellSnapIns");
return (string)section["SnapIn1"];
}
}-The XMLCheck应返回"WebAdministration“
发布于 2009-08-14 16:15:50
VS将app.config重命名为yourappname.exe,并将其与.exe放在bin目录中
你能确认文件存在于bin目录和你的exe中吗?
https://stackoverflow.com/questions/1278730
复制相似问题