app.config

  • Thread starter Thread starter Bragadiru
  • Start date Start date
B

Bragadiru

I have a solution with 2 projects: a class library(my.dll) + a windows
application (mine.exe). In exe project I have a reference to the dll. In
both I have app.config files, BUT only mine.exe.config file is generated in
\bin\Debug\ folder of exe app. What can I do to generate my.dll.config from
app.config ?

Thnx for any advice.
 
The app.config file is associated only with an exe, not a dll, so you cannot
have a your.dll.config.
However, from within the dll, you can access settings in app.exe.config.

rajasi
 
I created this class which lets you create a kind of app.config for dll's
Imports System.Xml

Imports System.Configuration

' usage:

' The xml file must be built like this

'<configuration>

' <assemblySettings>

' <add key="key1" value="Value for key1 (OtherTestLib)"/>

' <add key="key2" value="Value for key2 (OtherTestLib)"/>

' </assemblySettings>

'</configuration>

' Dim settings as AssemblySetting(filename)

' Dim var1 as string = settings("key1")

' Dim var2 as string = settings("key2")

' for enumeration

' Dim settings as IDictionary

' Dim entry as DictionaryEntry

'

' settings = AssemblySetting.GetConfig(filename)

' For Each entry in settings

'

' Next

Public Class AssemblySettings

Private mysettings As IDictionary

Dim entry As DictionaryEntry

Public Sub New(ByVal FileName As String)

mysettings = GetConfig(FileName)

End Sub

Default Public ReadOnly Property KeyValue(ByVal KeyName As String) As String

Get

Dim retVal As Object

If Not mysettings Is Nothing Then

retVal = mysettings(KeyName)

End If

If Not retVal Is Nothing Then

Return CType(retVal, String)

Else

Return ""

End If

End Get

End Property

Shared Function GetConfig(ByVal FileName As String) As IDictionary

Dim doc As XmlDocument = New XmlDocument()

Dim nodes As XmlNodeList

Dim node As XmlNode

doc.Load(FileName)

nodes = doc.GetElementsByTagName("assemblySettings")

For Each node In nodes

If node.LocalName = "assemblySettings" Then Return CType(New
DictionarySectionHandler().Create(Nothing, Nothing, node), IDictionary)

Next

End Function

End Class
 
Back
Top