开发者

Visual Studio Post Build Event Unable to access appsettings or webconfig

开发者 https://www.devze.com 2023-01-26 02:57 出处:网络
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 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 giv开发者_JAVA技巧ing 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");
0

精彩评论

暂无评论...
验证码 换一张
取 消