C# Visual Studio生成后事件无法访问appsettings或webconfig

C# Visual Studio生成后事件无法访问appsettings或webconfig,c#,visual-studio,C#,Visual Studio,我有以下代码 我在生成后事件中执行此操作,下面的类正在执行,但它无法访问appsettings 我尝试了所有的组合,比如提供绝对路径和通过configurationmanager访问,但都不起作用 下面的类在我们有web.config和appsettings的项目中 你能告诉我有什么问题吗 TestResources:AppDomainIsolatedTask { private NameValueCollection constants = (NameValueCollectio

我有以下代码

我在生成后事件中执行此操作,下面的类正在执行,但它无法访问appsettings

我尝试了所有的组合,比如提供绝对路径和通过configurationmanager访问,但都不起作用

下面的类在我们有web.config和appsettings的项目中

你能告诉我有什么问题吗

TestResources:AppDomainIsolatedTask
{
       private NameValueCollection constants = (NameValueCollection)ConfigurationManager.GetSection("applicationSettings/applicationConstants");

       public override bool Execute()
       {
          constants.Get("VersionNo")
       }        

}

你试过这样的东西吗

        var fileMap = new System.Configuration.ExeConfigurationFileMap { ExeConfigFilename = "path to config" };
        var config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
        var section = (NameValueCollection)config.GetSection("name of section");

@宫崎骏,我是否需要在该pathtoconfig中提供绝对web.config路径。@miyamot我收到以下错误:错误CS0030:无法将我提供的节名中的类型“System Configuration.ConfigurationSection”转换为“System.Collections.Specialized.NameVal Collection”/applicationConstants@gov-您能将您的问题编辑为包括配置文件。即。。。还有?它终于起作用了,我做了以下NameValueCollection nRet=newnameValueCollection();System.Xml.XmlDocument xDoc=new System.Xml.XmlDocument();字符串sXml=section.SectionInformation.GetRawXml();LoadXml(sXml);NameValueCollection nameValueCollections=(NameValueCollection)(新的NameValueSectionHandler()).Create(null,null,xDoc.FirstChild);