I'm having problems deploying a config file.
I have a set of default configurations, which are altered at the moment of installation (custom installer class).
But strangely, my settings keep being reset. In VS2005 all settings are defined with default value, but it's just not getting into my deploy software.
What can i do?
Thanks!
Could it be that you are somehow altering the wrong user.config file?
Each new version of your application gets a new folder under the folder below (Windows 7):
C:\Users>username>\AppData\Local\\App.exe_Url_fdtzgjq\
Each subfolder contains a separate user.config:
\0.5.0.0\user.config
\0.9.0.0\user.config
\1.0.0.0\user.config
etc.
Related
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 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
I have settings that were originally scoped as User settings. I notice that the main .config that lives in the same directory as the assembly is being ignored by .NET. If I change any setting it still always ends up with the default values at run-time. I was unable to find a copy of the config file in User AppData. I changed the settings' scope to Application and yet .NET is still ignoring the config file.
Where is the file it's trying to load instead? How can I get it to only use the .config file in the assembly's directory?
If you are using visual studio to run your application, visual studio regenerates the settings file every time you complete a recompile.
So if you change your settings within the application and rebuild & launch within visual studio, the settings file will revert to what values are stored in the visual studio project.
If you use Configuration manager to read settings from config file, it has to load data from appname.exe.config file. Try this code (you have to add reference to system.configuration assembly)
System.Configuration.ConfigurationManager.AppSettings["settings-name"];
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.