When I build a windows application. It does not work because it cannot read my app.config file. I looked in the bin directory and it does not have the appname.exe.config file. If I manually copy over the app.config and rename it the appname.exe.config the application will work..but when I build the project this file is never created automagically. What am I missing? Why is my project not creating it? I have looked through the whole folder structure and there is no other config files.
-
In the properties is it have copy local set to true? – bowlturner Aug 06 '15 at 15:40
-
@bowlturner -- it's not set to true by default. – rory.ap Aug 06 '15 at 15:41
-
@roryap That's why I asked. – bowlturner Aug 06 '15 at 15:44
-
1@bowlturner -- what I meant is that it doesn't need to be. The file should be generated anyway. – rory.ap Aug 06 '15 at 15:45
-
what is windows application? what is your project template? – Hamid Pourjam Aug 06 '15 at 15:50
-
Are you using custom build tools? – Hamid Pourjam Aug 06 '15 at 15:52
-
I am just using the regulard build option in visual studio. it is a windows forms application. There is not an option to copy local set to true, but does have the copytooutput directory which is set to do not copy. I have set this with also to copy, neither of which creates the exe.config file – Greg P Aug 06 '15 at 16:00
5 Answers
Everyone here is giving you false information I think. I think @bowlturner had it right. According to Microsoft, you do need to set the app.config
's Copy to output directory
property to either Copy Always
or Copy if newer
. From Microsoft's MSDN Site:
When you develop in Visual Studio, place the source configuration file for your app in the project directory and set its Copy To Output Directory property to Copy always or Copy if newer. The name of the configuration file is the name of the app with a .config extension. For example, an app called myApp.exe should have a source configuration file called myApp.exe.config.
Visual Studio automatically copies the source configuration file to the directory where the compiled assembly is placed to create the output configuration file, which is deployed with the app.
-
1**Visual Studio automatically copies the source configuration file to the directory where the compiled assembly is placed to create the output configuration file, which is deployed with the app.** This means you do not need to set "Copy to output directory" to `Copy Always` or `Copy if newer` – Hamid Pourjam Aug 06 '15 at 16:01
-
But that is the thing. with any of those settings it is not being created. – Greg P Aug 06 '15 at 16:02
-
@dotctor -- Yes, if you set the property to `Copy Always` or `Copy if newer`. Read the line above it: **When you develop in Visual Studio place the source configuration file for your app in the project directory and set its Copy To Output Directory property to Copy Always** – Icemanind Aug 06 '15 at 16:03
-
1create a simple console or winforms application and see the properties on app.config. – Hamid Pourjam Aug 06 '15 at 16:05
-
1@GregP - Delete your app.config file. Then right click on your project, and select add, add new item. Find "Application Configuration File" in the list and add it. – Icemanind Aug 06 '15 at 16:05
-
@dotctor - I created a Windows Application and added an `app.config`. By default, its set to `Do not copy` and it did indeed create the config file in the bin folder. But all I'm doing is quoting Microsoft's MSDN site. – Icemanind Aug 06 '15 at 16:09
-
@Icemanind - I have done that already and it didn't work. I just created a new project and it is still not doing it...frustration. – Greg P Aug 06 '15 at 16:53
-
I created a test windows form app and a console app..they already contained an app config, and it still is not creating..at a loss. – Greg P Aug 06 '15 at 16:57
The correct settings are:
Build Action = None
Copy to Output Directory = Do not copy
and very important, the project file needs to contain this element:
<ItemGroup>
<None Include="App.config" />
</ItemGroup>

- 16,340
- 13
- 78
- 118
The only thing that worked for me was to delete bin\ and obj\ entirely. Rebuild and the file is created fine.

- 3,640
- 3
- 20
- 24
-
Just to confirm with more details from my experience: I just had this happen when using Visual Studio 2019 (16.9.4) to build a .NET 4.7.2 console app. I copied an App.config into the project, and when I built the project it would not replace the default appname.exe.config in the bin folder. Tried various combinations of cleaning/rebuilding/deleting bin contents; finally deleting the bin/obj folders themselves fixed it. – hikarikuen May 06 '21 at 16:20
Look on App.config properties, should be:
BuildAction: None
CopyToOutputDirectory: Do not copy
Custom tool and custom tool namespace should be empty
Also try to Rebuild project. Right click on project -> Rebuild

- 334
- 2
- 12
Assuming you're using Visual Studio click your config file in the Solution Explorer and and in the Properties panel set Copy To Output Directory to something other than Do Not Copy.

- 339
- 4
- 13
-
2that will put `App.Config` in the Output Folder, but not `appname.exe.config` – Mark Aug 06 '15 at 15:45