Config File Project Output: Did they change this in 2005?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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

.



Relevant Pages

  • Debugging with VS2005 dynamic web-reference
    ... My client-side dynamic web-reference contains strings, ... substitute with user entries in my installer class. ... My installer class for the project substitutes server and directory ... How can I get the debug version to read the config file? ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • RE: Need to write into the App config file during the setup
    ... pass in the target directory to the installer class. ... directory and use the path to locate the application config file. ... Refer to MSDN on how to pass parameters from setup to your installer class. ...
    (microsoft.public.dotnet.framework.setup)
  • RE: Write to config file from deployment project
    ... It shows how to load the .config file and use XML to change values. ... > override does not seem to be called at all. ... > If you write an override in an installer class, how and where is this called? ... > I have looked at the Walkthrough for Passing Data to a Custom Action but the ...
    (microsoft.public.dotnet.framework)
  • Re: Using Webstart
    ... > "There is still no way for even a signed JAWS app to ... AFAIU, a signed JWS app. ... you arrange it in your own installer class. ... http://mindprod.com Java custom programming, consulting and coaching. ...
    (comp.lang.java.programmer)
  • Setup project accepting Command-Line params?
    ... I can get my setup application to display a dialog and pass entered ... values to the Installer class of my app. ...
    (microsoft.public.dotnet.languages.csharp)