38.4. Referenced Projects with Settings

As applications grow, it is necessary to break up the logic into assemblies that are referenced by the main application. In the past, if these referenced assemblies wanted to use an application setting, there were a number of gotchas that made it problematic. With Visual Studio 2008, it is now possible to share application settings among assemblies using the project properties designer. Figure 38-5 shows the Settings tab of the project properties designer for a reference assembly. In this case the Access Modifier drop-down has been set to Public to allow access to these settings from the main application.

Figure 38.5. Figure 38-5

To access this property from the main application, you can again use the generated strongly typed access properties:

ReferencedAssembly.My.Settings.Default.SecondaryServer

A word of caution about using the project properties designer and referenced application settings: If you examine the code-behind file for the settings designer, you will note that for each of the settings you have defined there is a strongly typed access property, as previously discussed. What is important is the DefaultSettingValueAttribute that is applied. This is significant because it determines the value that will be returned by this property if the configuration file does not have any value specified.

In the following snippet, the default ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.