I added App.Config to my project. I have an installer class (ProjectInstaller.cs) that needs to read values โโfrom App.config. I provide the keys. The following is sample code:
ConfigurationManager.AppSettings["CONFIG_FILE"]
I get null values โโaccording to the code above when called in the Installer class. But in the App.Config file there is a value for the specified key.
Try:
public string GetServiceNameAppConfig(string serviceName) { var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetAssembly(typeof(MyServiceInstaller)).Location); return config.AppSettings.Settings[serviceName].Value; }
Google helps: http://social.msdn.microsoft.com/Forums/ar/winformssetup/thread/896e110e-692d-4934-b120-ecc99b01c562
The fact is that your installer does NOT work as exe separately, and app.config called what you imagine will not load by default, because exe with your installer InstallUtil.exe , and ultimately it will look for appSettings from the InstallUtil.exe.config file, which is not yours and not what you want, read the following and check the links ...
If you call it through InstallUtil, then the configuration file is defined as InstallUtil.exe.config, which is not what you want. You can manually load the configuration file using Configuration, but it will probably be a little dirtyThe trick is in the context of executing installer classes. if you install the application using InstallUtil, all the code will be executed in the same process as InstallUtil.exe. If you need to transfer some data to the Installer Class during deployment, you must use the installation options. They are passed to the installer at run time Install, Commit, Chip and delete methods using the runtime (installutil, windows instller ...). You can access these parameters using the InstallContex property of the installer class.CodeProject has an excellent article on installation projects and options: http://www.codeproject.com/dotnet/SetupAndDeployment.aspCheck out http://msdn2.microsoft.com/en-us/library/system.configuration.install.installcontext.aspx
If you call it through InstallUtil, then the configuration file is defined as InstallUtil.exe.config, which is not what you want. You can manually load the configuration file using Configuration, but it will probably be a little dirty
The trick is in the context of executing installer classes. if you install the application using InstallUtil, all the code will be executed in the same process as InstallUtil.exe. If you need to transfer some data to the Installer Class during deployment, you must use the installation options. They are passed to the installer at run time Install, Commit, Chip and delete methods using the runtime (installutil, windows instller ...). You can access these parameters using the InstallContex property of the installer class.
CodeProject has an excellent article on installation projects and options: http://www.codeproject.com/dotnet/SetupAndDeployment.asp
Check out http://msdn2.microsoft.com/en-us/library/system.configuration.install.installcontext.aspx
David Piras explained very well why you cannot use your app.config and suggests passing your values โโas parameters.
I found a good and useful article on how to pass parameters to installutil.exe and use them in serviceInstaller or projectInstaller :
installutil.exe
serviceInstaller
projectInstaller
Part 1: Using Options with InstallUtil
Part 2: Configuring Windows Services with Settings from InstallUtil
It briefly explains how to pass arguments and how to read them.
For me, the easiest solution was to create the InstallUtil.exe.config file and fill it with the contents from the application configuration file. The service installer has successfully read from this configuration file.
I created my service by following these steps: WCF service host in a managed Windows service
Source: https://habr.com/ru/post/898507/More articles:CacheDependency from 2 or more other cache elements. (ASP.NET MVC3) - cachingA strange # _ = _ appears at the end of the url after response.redirect ASP.NET - .netIs there an online javadoc for the Android Phonegap API? - androidMYSQL Cluster (NDB) vs MongoDB - mysqlScalaz traverse_ with monk IO - scalaMake JLabel transparent again - javaIs it possible to use namedtuple with SQLalchemy? - pythonCreate vp8 on Android - androidAndroid ImageView rotation Embed the functionality of your site with strangers using Rails 3 (XSS vs iframes) - ruby-on-railsAll Articles