简体   繁体   中英

Visual Studio Post Build Event Unable to access appsettings or webconfig

I have the following code.

I am doing this in the post build event, the below class is getting executed but it is unable to make any access to appsettings.

I tried all combinations like giving absolute path and accessing through configurationmanager, but nothing worked.

The below class is inside the project where we have web.config and appsettings.

Can you please tell me what can be the issue.

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

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

}

Have you tried something like this?

        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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM