I have the following projects:
- MVC
- Console application
- Class library
- Windows Forms Application
- COM library
All of these applications must use a single configuration file. As far as I understand, app.config files are for windows, console applications and class libraries when web.config are for web projects.
The same configuration should be available in all of these projects. I read that he suggested using the machine configuration file, but we will not always have access to it, so the configuration files should be inside our solution.
I do not quite understand how configuration files are created. I have currently written a simple project in which I have the following:
- Class library for storing configuration files. And they tried to do it through reflection.
- A Windows application that should read app.config from the class library.
When I execute the following code, I expect to get a configuration file with test values:
_applicationSettings = ConfigurationManager.OpenExeConfiguration( System.Reflection.Assembly.GetAssembly(typeof(WCSConfiguration)).Location ).AppSettings;
Instead, I get an empty application settings file.
The class library has the following App.config file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="TestTextKey" value="TestTextValue"/> </appSettings> </configuration>
I tried using the .GetExecutingAssembly() method, which I expect to return the assembly of code that is currently executing. This did not work; instead, it returned the build of the Windows application.
GetAssembly(type(WCSConfiguration)) returned the right assembly, however the configuration file was not in the bin / debug directory.
I have a feeling that either I'm doing something fundamentally wrong, or Microsoft has not made it flexible enough. I also tried to find the MSDN for an explanation, but this was not well documented by IMO.
I also left COM in bold because I'm not sure that any configuration files will be available for the COM library at all. Firstly, I would like other projects to work.
I understand that this is a lot of information. Any help would be greatly appreciated. Earlier, we decided to use the registry, but this turned out to be unpleasant, mainly because access to the registry is not available in some scenarios. In addition, now we have several versions of applications, and the transition between branches is half an hour :(
thanks
Edit:
If I add dll configuration sections to app.config, this means that these options will be available only from this application. Please correct me if I am wrong. The example I provided is a shortened version. In total there are about ten window applications, one MVC project and a set of class libraries, all of which should use this configuration.
Configuration parameters are mainly connection strings, search values ββthat are not included in the database, and several other minor settings. The main problem with this question is the connection strings. There are several minor releases of the application in which each release points to a different database.
What I would like to get from this is a good workable solution so that it can be published on the Internet, and other people who are faced with the same problem will not waste days of their time.
IMO story moral: Use both App.config and Web.config to store the location of your own configuration file.
Write a simple XML serializer for reading / writing configuration and a DLL for serving the configuration.
COM objects are a long history and were implemented using a βhackβ, since neither App.config nor Web.config are available in the COM DLL.