I had occasion tonight to write an installer class that changed
something in a config file tonight (I had never had a need to do it,
but happened upon a "How To" article that explained it in terms of a
web app and decided to try it with a regular app). What I discovered
was that for some reason the .config file is not being copied with
Primary Output. In checking a few other apps for which I had written
installers I found that they too lacked .config files. I could have
sworn that 2003 deployed these automatically -- am I wrong?
Here is the custom installer class that I used (it's just a tweek of
the m$ code)
Imports System.ComponentModel
Imports System.Configuration.Install
Public Class WebServiceInstaller
Public Overrides Sub Install( _
ByVal stateSaver As System.Collections.IDictionary)
MessageBox.Show("Started")
Dim installlog As New System.IO.StreamWriter("c:\Installation.log")
installlog.AutoFlush = True
Try
Dim ProvidedName As String =
Me.Context.Parameters.Item("ServerName")
Dim ServiceName As String =
Me.Context.Parameters.Item("ServiceName")
installlog.WriteLine("Starting edit of config file")
If (String.IsNullOrEmpty(ProvidedName) _
OrElse String.IsNullOrEmpty(ServiceName)) Then
Throw New InstallException("No arguments specified")
End If
'use reflection to find config file
Dim assem As System.Reflection.Assembly = _
System.Reflection.Assembly.GetExecutingAssembly()
Dim strConfigLoc As String = assem.Location
installlog.WriteLine(strConfigLoc)
Dim strTemp As String = strConfigLoc
strTemp = strTemp & ".config"
Dim finfo As New System.IO.FileInfo(strTemp)
installlog.WriteLine("File Info: " & strTemp)
If (Not finfo.Exists) Then
Throw New InstallException("Missing config file")
installlog.WriteLine("Missing config file")
Exit Sub
End If
'load document into xml dom
Dim xmldoc As New System.Xml.XmlDocument()
xmldoc.Load(finfo.FullName)
'find the right node and change the value
Dim nod As System.Xml.XmlNode
Dim FoundIt As Boolean = False
For Each nod In xmldoc.Item("configuration").Item("appSettings")
'skip comments
If nod.Name = "add" Then
If (nod.Attributes.GetNamedItem("key").Value = _
"CryptoWebServiceConsumer.CryptoWS.Service") Then
nod.Attributes.GetNamedItem("value").Value = _
"http://" & ProvidedName & "/" & ServiceName & "/Service.asmx"
FoundIt = True
End If
End If
Next nod
If (Not FoundIt) Then
Throw New InstallException("Config file did not contain a
ServerName section")
End If
xmldoc.Save(finfo.FullName)
Finally
installlog.WriteLine("Ending edit of config file")
installlog.Close()
End Try
End Sub
End Class