Deleting app.config file

  • Thread starter Thread starter Kyle Blaney
  • Start date Start date
K

Kyle Blaney

Suppose myApp.exe.config contains a redirection from version 1.0 of
someAssembly to version 1.1 of someAssembly.

When a user deletes myApp.exe.config and version 1.0 of someAssembly
is installed on their machine, myApp will continue to run but will use
version 1.0 of someAssembly. This is worse than the behaviour when a
user deletes an assembly that my application needs. At least in that
case my application won't even run. It is more dangerous that my
application continues to run but runs with a version of an assembly
that was not intended.

How do I ensure that myApp runs with the config files I distribute?
 
You could query the runtime version (I think System.Environment provides
some help there). Or you could use reflection on a System type to get the
assembly and check it like that, in code.

-mike
MVP
 
A few options:

Use MSI. It will detect that the file was missing and replace it.

Set a value in the appSettings area that you can validate against to ensure
that the config file is present and current.

HTH;
Eric Cadwell
http://www.origincontrols.com
 
The best approach I have found so far is to compile the config file
into the application by changing the config file's build property from
"None" to "Embedded resource". When this is done, Visual Studio .NET
still renames app.config and copies it into the application's bin
directory. However, you can delete it from there (because it's part
of the assembly) and everything works fine.

The disadvantage of this approach is that changes to the config file
require the entire application to be recompiled.

Kyle Blaney
 
Back
Top