can vb.net2003 create config file in bin directory?

R

Rich

Hello,

I picked up this example on using the Reflection namespace
for loading forms/classes on the fly at msdn

http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnadvnet/html/vbnet10082002.asp

which uses a config file named "yourAppName.exe.config"
which is an xml based config file that references dlls in
other projects to load their forms/classes on the fly.
This config file resides in the bin directory of the
app's .exe. The example works great (although written in
vb.net2002 - for vb.net2003 need to instantiate a var:
ClassConfigValues = New Specialized.NameValueCollection )

The problem I am having is that when I run the app in
debug mode - the app's bin gets recreated each time, and I
have to manually recreate/copy the config file into the
bin. The config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="availableclasses"
type="System.Configuration.NameValueSectionHandler" />
</configSections>
<availableclasses>
<add key="First Form"
value="C:\Newforms\FirstForm.dll~FirstForm.Form1"></add>
<add key="Second Form"
value="C:\Newforms\SecondForm.dll~SecondForm.Form1"></add>
<add key="Third Form"
value="C:\Newforms\ThirdForm.dll~ThirdForm.Form1"></add>
</availableclasses>
</configuration>

Is there a way for vb.net2003 to add this config file to
the bin at rebuild time? Or is it a deal where you create
the app and manually add the file yourself?

Thanks,
Rich
 
J

jim

hi rich,

just add the config file to your solution with the (default) name of
App.Config... when you build your project/solution App.Config will be
automatically renamed and moved to the bin directory.

hope this helps,

jim
 
R

Rich

Cool! I learned something new. That worked great. One
question though on this example. The big deal is that it
says with Reflection you can instantiate forms/classes on
the fly which are created later and in a different
project. But from what I understand, you have to include
a reference to these new objects in the config file which
suggests that you will have prior knowledge of the
existence of these objects. Wait. I think I am answering
my own question - you can add this config file at a later
time. So my original question of do you manually plant
the config would be either or. I could include a config
file in the solution or I could add a config file after
the fact. Well, anyway, I learned something :). I guess
the real deal is to stuff these two guys for just-in-case.

Imports System.Configuration
Imports System.Reflection

Rich
 
H

Herfried K. Wagner [MVP]

* "Rich said:
which uses a config file named "yourAppName.exe.config"
which is an xml based config file that references dlls in
other projects to load their forms/classes on the fly.
This config file resides in the bin directory of the
app's .exe. The example works great (although written in
vb.net2002 - for vb.net2003 need to instantiate a var:
ClassConfigValues = New Specialized.NameValueCollection )

The problem I am having is that when I run the app in
debug mode - the app's bin gets recreated each time, and I
have to manually recreate/copy the config file into the
bin. The config file looks like this:

Rename the file to "App.config", put it in the project's source folder
and add it to the project. VS.NET will automatically copy the file to
the "bin" directory and rename it appropriately.
 
R

Rich

Thank you. I did that now, and it worked fine. May I ask
if it is possible to create/generate an App.Config file
from within the code? For example, if I have an already
existing app (with all the required imports), and I want
to reference some new objects (forms/classes) from another
project, can I input their information into my existing
app like through a form textboxes such as to generate the
config file on the fly or does that require recompiling?
Or is it possible to just create/generate an app.config
file from within the code at all?

Thanks,
Rich
 
H

Herfried K. Wagner [MVP]

* "Rich said:
Thank you. I did that now, and it worked fine. May I ask
if it is possible to create/generate an App.Config file
from within the code? For example, if I have an already
existing app (with all the required imports), and I want
to reference some new objects (forms/classes) from another
project, can I input their information into my existing
app like through a form textboxes such as to generate the
config file on the fly or does that require recompiling?
Or is it possible to just create/generate an app.config
file from within the code at all?

You won't need to recompile, that's the main advantage of a config
file. Nevertheless, config files should not be used to store user
preferences. You can edit them with .NET's 'System.Xml' classes.
 
J

Jay B. Harlow [MVP - Outlook]

Rich,
I normally include a skeleton config file when I deploy my app, then add new
specific types later.

As normally I am either loading a collection of dynamic types, using a
DictionarySectionHandler. Or I have a "default" implementation of a single
dynamic type, that the end user is able to replace later.

Also giving the skeleton config file, allows the end user (and me!) to know
the correct syntax to use to add the new dynamic type later...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top