views:

239

answers:

3

Much to my annoyance, Visual Studio 2010 added App.config files to all of my .EXE projects when I changed the target from .NET Framework 3.5 to .NET Framework 4.0. So my automated build broke until I checked those new files in.

Is there any particular reason I can't just delete these App.config files? Or is Visual Studio going to keep adding them to my projects?

I'll refrain from ranting about a tool that adds useless files to my projects . . .

Clarification:

I understand what app.config is for. What I don't understand is why Visual Studio 2010 would add an app.config file to an existing project when I change the project to target .NET 4.0 rather than .NET 3.5. My application doesn't require anything from app.config in order to run, so my only reasonable conclusion would be that either Visual Studio for some reason needs the app.config in order to compile, or somebody decided that they know better than me and my application must have an app.config even though I don't want one.

Oops ... I ranted.

Further clarification:

Converting a project from Visual Studio 2008 to Visual Studio 2010 is not the problem. It's when I change the target from .NET Framework 3.5 to .NET Framework 4.0 that the app.config gets added to the project. The app.config contains this:

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

When I change it back to target .NET Framework 3.5, the app.config file is modified to read:

<supportedRuntime version="v2.0.50727"/>

I think I see what they're trying to do, but adding that app.config file automatically was a really bad idea.

+2  A: 

The app.config file is not necessary. Applications will run just fine without them.

EDIT

Reed pointed out there is one case where this is not true that's worth noting

There is one situation where it is required - if your project references a CLR 2.0 mixed-mode assembly, you must have an app.config file to run

JaredPar
Any idea why VS 2010 so helpfully adds one to a converted project?
Jim Mischel
@JaredPar: There is one situation where it is required - if your project references a CLR 2.0 mixed-mode assembly, you must have an app.config file to run.
Reed Copsey
@Reed, interesting. Didn't know that. Will update my answer.
JaredPar
+2  A: 

There was probably some setting that needed to be added in the config file in the conversion, if you create a new project you don't get an app.config automatically.

You would have to check what it contains to determine if there is something in it that is needed.

Guffa
The point is that there was no app.config in my project, and it ran just fine. For unknown reasons, VS 2010 added an app.config when I converted the project. So there wasn't any setting that needed to be changed.
Jim Mischel
Unfortunately, the conversion tool just always adds this, whether or not it is necessary.
Reed Copsey
+5  A: 

The only time I know of that app.config is required in a .NET 4 project is if you reference a CLR-2.0, mixed mode assembly. In that case, you need to add useLegacyV2RuntimeActivationPolicy="true" into the startup element, or you'll get errors at runtime.

However, the VS conversion tool does not detect this, and adds an app.config file by default that is really not necessary. If you are able to run after the conversion, this is likely not an issue for you.

Otherwise, you are free to delete it (unless, of course, you're using it for other purposes).

Reed Copsey
Thank you: "...and adds an app.config file by default that is really not necessary." Grrr.
Jim Mischel