c# Windows service is it (possible) to use the app.config

后端 未结 2 1903
小蘑菇
小蘑菇 2021-01-17 16:39

I am developing a windows service, and I am almost done,

I am doing that using Visual Studio 2012.

I am connection to the App.config file in ord

相关标签:
2条回答
  • 2021-01-17 17:12

    An even simpler approach would be to read the specific config file according to a specific path! Here's a working sample:

    System.Configuration.Configuration conf = System.Configuration.ConfigurationManager.OpenExeConfiguration("<full path including component name.exe (and not including the '.config' part");
    string PropValue = conf.AppSettings.Settings["PropertName"].Value;
    
    0 讨论(0)
  • 2021-01-17 17:21

    Yes you will be able. When you will compile your service, you will need to deploy the whole /bin directory. It will contains the service dependencies and actual code.

    Once compiled, the App.config file will be renamed to: Service.exe.config. The content will be a copy of the App.config. This is the file that will be used by the service. Service.exe is the name of your executable. So if your executable is AwesomeService.exe the config file will be AwesomeService.exe.config.

    0 讨论(0)
提交回复
热议问题