Harsh Suman
Harsh Suman

Reputation:

Storing Settings for Multiple Projects Commonly in C#

I want to keep the settings for two different projects for c# commonly.Is there any way to achieve this?.

Regards, Harsh Suman

Upvotes: 1

Views: 1413

Answers (2)

Brian ONeil
Brian ONeil

Reputation: 4339

If by project settings you mean configuration information then the solution already posted about setting a common file for appSettings is fine (assuming that you are using the appSettings section for your configuration). You can also make a custom configuration section handler that loads from a common place or even a database.

If you are talking about project information, like Assembly type of information, then you can edit the project file and include a link to a common file that will be compiled into both of the projects. You can add the link by including something like this...

<Compile Include="..\..\SolutionInfo.cs">
  <Link>Properties\SolutionInfo.cs</Link>
</Compile>

We use this for common attributes across projects that are either in the same solution (like to align version numbers, etc) or across various projects to have one place to manage common information like company information.

Upvotes: 1

Yossi Dahan
Yossi Dahan

Reputation: 5377

I guess there are many options to choose, from, depending on your exact scenario and preference.

Here are some -

You could use a database, if you can safetly assume there is one.

you could use entries in the machine config, which would be accessible to both applications; you could do so using AppSettings or, better yet, custom configuration section.

You can declare your configuration in the machine config, but specify it in a separate file to make it easier (and safer) to maintain -

<configuration> .. <appSettings file="MyConfig.config" />...</configuration>

Where MyConfig.config is the name (can be a path to any subfolders as well) of a file containign an appSettings section.

If you're using custom configuration (or any build in configuration section, other than appSettings) you can use the ConfigSource attribute to specify the location of your configuration as described here

You can look at using some shared location for the configuration, for example - in Windows Vista you can make use of the %APPDATA% location to store the configuration (create your own folder under that), looking at this folder you will notice this is what many other programs do.

Upvotes: 4

Related Questions