473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

Nov 21 '05 #1
5 1555
If the file was app.config, then it is copied and renamed to
appname.exe.config. If it is something else it should be copied if you
have set its build action property to Content.

Nov 21 '05 #2
stand__sure,
Check the properties of you app.config file in solution explorer.

There is a new option that indicates Copy or Copy if Newer. I noticed it on
Sql Server 2005 Express data files.

It sounds like your app.config may be set to Copy if Newer, instead of
always copying...

Hope this helps
Jay
"stand__sure" <st*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
|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
|
Nov 21 '05 #3
that part works as expected -- it's that myapp.exe.config is not being
picked up by the setup/deployment project

Nov 21 '05 #4
Jay,

I'm not seeing this option in the property pages... (I guess I should
get around to installing beta 2 which will probably eliminate this
issue)

Thanks,
stand__sure

Nov 21 '05 #5
stand__sure,
Doh! misread the part about "Primary output".

When I get back to my 2005 VPC I will try beta 2 to see how it behaves...

BTW: Have you tried asking in the VS 2005 communities?

http://forums.microsoft.com/msdn/

Hope this helps
Jay

"stand__sure" <st*********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
| Jay,
|
| I'm not seeing this option in the property pages... (I guess I should
| get around to installing beta 2 which will probably eliminate this
| issue)
|
| Thanks,
| stand__sure
|
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: DraguVaso | last post by:
Hi, I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application...
5
by: Paul Daly (MCP) | last post by:
I've created a windows forms appliation that gets its data from a sql database. I want to create an app.config file for this application so that in the event that the server name changes, they...
9
by: ALI-R | last post by:
Hi,, I have two questions : 1) Is it mandatory that config file of a desktop application must be App.config 2) Is it possible to update config file in your code?? thanks for your help. ALI
5
by: feng | last post by:
Hi, We just converted our VB.Net Windows exe project from VS.Net 2002 to VS.Net 2003 and ran into a problem. the MyApp.exe.config file that we use for our customized configuration settings is...
5
by: MJB | last post by:
I have several dlls that have app.config files tied to them. When adding their primary output to a Setup project everything works fine, but only the app.config for the .exe gets added to the Setup...
6
by: TS | last post by:
I cannot get this to work. I added an app.config to a project i reference from my web application project (vs 05) but can see no way to access the settings within it. the other thing is that I...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
3
by: =?Utf-8?B?RHVrZSAoQU4yNDcp?= | last post by:
I've added a web deployment project and want to use the config section replacement but I'm obviously not understanding something. I have set up an alternate appSettings file,...
10
by: =?Utf-8?B?TUNN?= | last post by:
When creating a new VB Web Application Project with VS2008, there are several settings (compiler settings, option strict, etc) that appear both in the web.config file and "My Project". I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.