I changed the target .NET framework of my WPF app from 3.5 to 4.0.
After making this change, I noticed that an app.config file was generated by VS2010 and placed in the main project folder. Its build action is set to “none — do not copy”.
This app.config file contains the following XML:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
The .csproj file for my project contains:
<Project
ToolsVersion="4.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Questions:
- What is the difference in meaning between
<supportedRuntime version="4.0"in app.config and<Project ToolsVersion="4.0"in .csproj? Does one override the other or do they actually mean different things? - Does the app.config file do anything if not copied to the output directory?
- Can I delete the app.config file without breaking anything?
Edit
One more question:
If I create a WPF 4.0 app from scratch, why is no app.config file created by default? (And doesn’t this imply that the file is unnecessary?)
This Microsoft blog article explains it pretty well:
http://blogs.msdn.com/b/jgoldb/archive/2010/04/12/what-s-new-in-net-framework-4-client-profile-rtm.aspx
Specific Answers:
As SLaks said, the .csproj settings tells the compiler what framework version to use, while the app.config file is used by the runtime (CLR) to determine which (if any) framework version the user needs to download.
app.config will be copied to the output even if the build action is "none — do not copy". app.config is a special file that will automatically be renamed to "[name_of_app].exe.config" then copied to the output directory.
For WPF 4.0 apps, app.config can be omitted if the app targets the .NET 4.0 Client Profile. If it targets the full .NET 4.0 framework (which includes things like asp.net), the file must be kept.
The reason this file is not created by default is that WPF 4.0 apps target .NET Framework 4.0 Client Profile by default. Since the runtime will assume that all .NET 4.0 apps need only the Client Profile installed, everything will be fine.