Kahn Kah
Kahn Kah

Reputation: 1453

Using App.Config in a Windows Service in C# / Visual Studio

I have created a Windows Service that reads various paths from the app.config file and works correspondingly.

I also use the 'Visual Studio Installer' as a installer for my Service.

This is my project structure:

enter image description here

However, when I build the Installer, it does generate the .msi and .exe used to install my service, but it doesn't include the config file that it needs to use to fetch the paths it's using:

enter image description here

Normally, the only thing that I use is the .msi file to install and run the Windows Service (it works perfectly using hardcoded paths) but I can't seem to use it in combination with the config-file.

What I tried is to copy the config file from the service project, and paste it in the folder of the second screenshot, but the service doesn't work when I try to install and run it that way.

What am I doing wrong?

EDIT

I tried adding the .config file manually in the installer project:

enter image description here

Without success however

Upvotes: 1

Views: 1928

Answers (1)

Nothing.

App.config is a part of the Service project and NOT of the installer.

It will be in the target installation folder of your Service assembly after installing.

Also App.config will be renamed according to the project's assembly name.

Example

Your assembly name is Watcher.Service, your .exe will be, after compiling Watcher.Service.exe and your app.config now will have the name Watcher.Service.exe.config.

Upvotes: 2

Related Questions