Introduction
Sometimes it is required to make the Windows service name configuration based. It means service name will fetch from App.config and install the service with the same name. In a simple way, it is not fetching the correct value from App.config at the time of installation. Because the exe running Installer is InstallUtil.exe and ConfigurationManager will look for InstallUtil.exe.config, it provides the wrong result. Follow the below steps to achieve this.
Sometimes it is required to make the Windows service name configuration based. It means service name will fetch from App.config and install the service with the same name. In a simple way, it is not fetching the correct value from App.config at the time of installation. Because the exe running Installer is InstallUtil.exe and ConfigurationManager will look for InstallUtil.exe.config, it provides the wrong result. Follow the below steps to achieve this.
Implementation
Step 1
Add following appSetting key in App.config to have service name.
- <?xml version="1.0" encoding="utf-8"?>
- <configuration>
- <startup>
- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
- </startup>
- <appSettings>
- <add key="ServiceName" value="ServiceMonitorV1"/>
- </appSettings>
- </configuration>
Next, right click on App.config and select properties. Change below two properties values,
Build Action -> None
Build Action -> None

Join the conversation! Your thoughts help the community grow.