Sharing application settings across projects in VS2005 (and VS2008)
|
Kathleen Dollard's recent "Ask Kathleen" column in Visual Studio Magazine talks about an improvement in VS2008 IDE that makes it easier to share Settings and Resources by allowing you to set the scope (which in VS2005 is Friend) to Friend OR Public. She then goes on to focus on the issue of Namespaces once you have the settings created in a way that can be shared.
When the settings are Public, you can easily access them from any project that has a reference to the project where the settings live. In Visual Studio 2005, however, this is more difficult, because the settings are always marked as Friend. In this case, Kathleen suggests (with caveats) is to just edit the generated settings class and change the scope. This is something I don't like to do, so I thought I would share my solution for sharing settings. In my solution, I create a project that is just for settings and resources. In a big app, I might split these into two separate projects. After creating my settings, for example:
Public Class Common Public Shared ReadOnly Property ConnString() As String Get Return My.Settings.connString.ToString End Get End Property Public Shared ReadOnly Property MessageBoxTitle() As String Get Return My.Settings.MessageBoxTitle End Get End Property Public Shared Property UserColor() As System.Drawing.Color Get Return My.Settings.UserColor End Get Set(ByVal value As System.Drawing.Color) My.Settings.UserColor = value My.Settings.Save() End Set End Property End Class The properties are Shared so that there's no need to instantiate the class when I want to use it. Now when I am in another project that has a reference to my AppSettings project, I have easy access to my settings.
|





Comments (1)
Try this
http://blog.decarufel.net/2007/10/getting-access-to-settings-in-another.html
Posted by Eric De CArufel | January 21, 2008 9:11 PM