I developed a windows service using Visual Studio 2012.
This service has a config file. When the application is build, the config file takes the name of the exe + .config.
If I install the service everything works, it means that the service uses the settings in the config file.
If I want to change a value in the config file and I restart the service, it does not read the new values, but it is still using the original values.
It looks like if the config file is copied in a different location when I install the service and the config file is not used anymore. Why? Where is the config file that service reads?
If you use .NET settings which you create in Visual Studio, then they are saved under
c:\Users\{Username}\AppData\Local\{AppName}\
this should work as you describe. you just have to be sure that you modify the correct .config file.
To check where your app resides, open the windows task-manager, right-click your exe and click 'properties'. here you can see the folder you app is running
Related
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:
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:
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:
Without success however
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.
I am trying to deploy a windows forms application which uses the properties/settings of the project to store config information.
In a form it is retrieved and sometimes changed by saving as below
Properties.Settings.Default["name"] = textBox1.Text;
Properties.Settings.Default.Save();
I only need to deploy to 3 PCS. Is it enough to deploy the .exe file alone?
Or do I also need the exe.config file ?
Thanks
If your App.config1 file contains default configuration information not embedded in your program, such as a connection string, then yes, you will need to bundle it with your executable.
However the code you've posted shows you're using the "Settings" feature, which is a feature of .NET that runs on-top of App.config. If you use the Settings feature, then your app.config file is (usually) actually stored under your current user's AppData directory and not the same directory as the executable, these files are also created as-required, in which case you won't need to ship the app.config file... assuming you have nothing else in the file.
With a Windows Forms (or WPF) application, if I create an installer through Publish command (ClickOnce that is), the installer creates application folder with executable and config file in C:\Users\[UserName]\AppData\. On the other hand, if the installer is created through Setup project (MSI), the installed app would be in C:\Program Files\My Company\My App with both the executable and the config file. Out of the two, I chose MSI path.
My expectation was that the application settings (as in Project properties > Settings tab) are read from/written to the config file that is in Program Files, which remains there even if I uninstall the program or upgrade it with a newer version, so that user's settings don't get lost. But it doesn't appear to be the case. Even that the Program Files version of the config file is there, the installed application appears to be reading from/writing to C:\Users\[UserName]\AppData\ as if it were a ClickOnce app. What am I missing?
(This is VS2010 + Win7 + C# + .NET 4.0 Client Profile, though I don't think those things have anything to do).
I hope I understand your question in the right way.
If you want to know, why settings are read from/written to the AppData folder, then it's because of security/permission reasons.
When first starting your application, your initially application settings from app.config file were copied to that folder. Your application will automatically work on that newly created file.
This is done, because it's a risk letting the user work on the "global" settings in your Program Files folder, with which all your users will work. Think about what would happen, if a user only has permissions to read, but not to write to this file.
I have installed a C# Windows Service on Windows Server 2008. I installed it with InstallUtil. The service reads some data from the app.config file and it is doing it fine. Can you tell me where this file is located after installing the service?
I have been looking for hours but can't find it.
You can verify the exact location of the installed Windows Service by following the steps below:
Bring up the list of Windows Services by clicking the "Services" icon under the "Administrative Tools" icon. You can also get this list by typing "View local services" in the Search Menu under the Start Menu.
Select your Windows service in the list of installed services, right-click and then select Properties. You can also double click on row representing the service.
Locate the "Path to executable" value on the Properties dialog box. The value will include any command line parameters.
Open the folder in which the service executable resides.
If the Windows service has been built with .NET Framework, its configuration will be stored in the corresponding .config file, i.e., the name of the executable suffixed by ".config", e.g., if the name of the executable is "XyzService.exe", then the name of the .config file will be "XyzService.exe.config".
A couple of things to note:
If you installed the service after building it on the same machine using say, Visual Studio, then Visual Studio would have transformed the App.config file from the project and placed it in the build output folder automatically (and renamed it appropriately using the above naming convention).
If your machine is set to hide file extensions in Windows Explorer, you will see 2 files "XyzService" and "XyzService.exe". In this case, the "XyzService.exe" is your config file. If you then switch off the option to hide file extenions in Windows Explorer, you will then begin to see "XyzService.exe" and "XyzService.exe.config".
If you cannot find a corresponding .exe.config file, then it is possible that the code within the service is falling back to default values. In this case, you can place a properly named and formatted config file alongside the service executable and then restart the service and everything should be fine.
According to Microsoft
For client executables, the application configuration file resides in
the same directory as the application's executable and has the same
base name as the executable with a .config extension.
Note, if your exe is called appname.exe, and you have Windows explorer set to hide extensions, then your application will display as appname and your config file then it will be displayed as appname.exe (even though the true name is appname.exe.config)
As others have pointed out, InstallUtil doesn't do anything with the config file and it should have copied to the server in the same manner as the exe itself.
It is the same location from where you have registered service using installutil tool.
The App.config is likely called {ProjectName}.exe.config given the fact that it is a Windows Service. Check to see if that file exists and is what you are looking for.
The same place where your application (Windows Service) is.
Check it out, if it's not there place it in the same directory as of service.
If you have a live environment (and from your question it seems like you do), you can check what's actually happening using the superior Process Monitor utility. But usually the .config fileis located right next to the .exe, and named the same.
I have a Windows application developed using Visual Studio 2008 (C#).
It has a app.config file, where various configuration related information are kept. After creating an installer for the project and installing it, there are no app.config file being copied to the installed directory. However, the functionalities that rely on settings in this file seem to work.
Now one of these settings is a database connection string, which obviously needs changing when installed in a different PC. My question is, how to have the app.config file available with the Setup file so that it can be configured later?
The app.config is copied/renamed <assembly name>.config as part of the compilation process, and placed in the bin directory. If you're using a Visual Studio Installer project (blech!), then it should have picked it up also and included it in the installer, IIRC.
(In response to your comment to both answers)
You can't keep using it as "app.config". The .NET config system searches for the configuration file whose name is the same as the entry assembly. If you renamed the file back to "app.config", then the configuration classes would stop working.
Your app.config file gets renamed on compilation, with the name of the binary. I.e. if your binary is myapp.exe then your app.config will be renamed to either myapp.config or myapp.exe.config.
This is the file that you should add to the setup package in order to use it on deployment for configuration.