Hi,
I have 2 projects in my VS 2010 solution (both using C#), and would like to have Application Setting in one project and access it from the other project. I have been doing some reading on this, and these Properties seem to be specific to a specific project. However, is there any way of either accessing the property value of one of these projects from a different project? (example below). Second best to set it in one project and have that value copied across automatically to the same property name on the other project?
I looked at a few different options, and came across property manager, but that appears to be used for C++ only, and as above I am using C#.
In Properties (Settings.Settings) from the main project (Project1):
Name: Type: Scope: Value:
Test1 String Application PC1
I can access these easily from any classes in Project1 by using Properties.Settings.Default.Test1 (or Project1.Properties.Settings.Default.Test1). However, when I try to access this value from classes in the other project (Project2), it won't let me, and says that I need to have this specifically set in the Properties for this second project. So, I just want some way of accessing this Test1 value from Project2 (something like Project1.Properties.Settings.Default.Test1 from a class in Project2, either using get and set in Program.cs of Project1, or some other way. Any suggestions on how to do this appreciated, and some code examples would be great.
Thanks.
Stephen ClarkePosted Mar 1, 2011, 1:25 PM
Hi folks,
Thanks for your reply and suggestions about the XML reader. However, I had a further look at this 'm not sure if this would be appropriate.
Overall I have a main application (project), and a service project which is part of the main application. When my application is installed (from the msi) I have a form which gets the value for a setting from the user and then writing that value to the appropriate setting of the main application (project). However, I can't also write to the service project as this part is installed later in the installation process. Overall what I would really like to do is to copy the value of a certain setting (contained within app.config), to the setting (app.config) in the service project.
Stephen
Sam HobbsPosted Mar 1, 2011, 12:32 AM
The Properties (Settings.Settings) are stored on disk in files with the extension "config"; they are XML files as Frogleg says. The IDE and related clases are designed for relatively simple purposes. It makes sense to me that your requirements are relatively common but I don't know how conducive the config files are for what you need. I assume there are plenty of solutions developed by others but I don't know of any.
I don't know if you intend to enhance your software much more. One possibility might be to make a third project that is designed to manage the settings. It could be used by the other projects. So that is a suggestion but I am sure there are many other possibilities. If you don't get an approriate answer in a few days then create a new thread with a more general subject that is also more specific to your requirement for managing settings for multiple projects.
FroglegPosted Feb 28, 2011, 1:09 PM