Share via


How to get app,config to stop overwriting myApp.exe.config (Winform)

Question

Thursday, June 4, 2009 12:05 AM

In my solution, project C# ( VS 2008 ) folder I have applicationName.exe.config - exactly matching the config file of app.config's output to bin. On the applicationName.exe.config I have the property set to copy always.  If I delete the applicationName.exe.config in the bin, the app.config is used to update it. If I drop a copy of  my custom applicationName.exe.config into the location, it gets overwritten by the app.config.

If I change the name of the file from windows explorer of applicationName.exe.config at the proj folder, then the build will tell me it cant find it to copy to bin.

I have a similar program ( I did not write ) - but its applicationName.exe.config always is the one left after the compile.

It seems as if in the old application, the applicationName.exe.config is copied last, but in my application app.config goes last and overwrites mine.   Can this be controlled ?

If you have any suggestions - please...  I use the custom config for various test scenarios.

Thanks !

andrew

All replies (5)

Thursday, June 4, 2009 9:28 AM ✅Answered | 1 vote

Hi andrew,

 

Let’s make the problem clearer by introducing such an application.  We have two configuration files in our project.  One is app.config and the other is applicationName.exe.config.   The applicationName.exe.config is set to Copy Always and the app.config is set to Do not Copy by default.  After each build of the solution, the applicationName.exe.config file will be first copied to the application folder (..\bin\.), because we set Copy Always for this file.  Then if the app.config is newer than the applicationName.exe.config (checking timestamp, last modified time), the app.config will be copied to the application folder and the original file is overwritten.   We can retrieve these information from Visual Studio MSBuild verbosity logs.  In menu Tools à Options à Projects and Solutions à Build and Run à set MSBuild project build output verbosity to Diagnostic, then each time we build the solution, we will get the detailed logs in the Output window.  

 

Here are some respresentative log records:

=======================================================================================

 

Copy the applicationName.exe.config to application folder:

“Target "_CopyOutOfDateSourceItemsToOutputDirectoryAlways" in file "C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets":

*  Task "Copy"*

*    Copying file from "D:\Projects\VS2008Projects\CSApplicationSettings\CSApplicationSettings\CSApplicationSettings.exe.config" to "bin\Debug\CSApplicationSettings.exe.config".*

*    Command:*

*    copy /y "D:\Projects\VS2008Projects\CSApplicationSettings\CSApplicationSettings\CSApplicationSettings.exe.config" "bin\Debug\CSApplicationSettings.exe.config"*

*  Done executing task "Copy".”*

 

Copy the app.config to application folder if it is newer:

“Target "_CopyAppConfigFile" in file "C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets":

*  Building target "_CopyAppConfigFile" completely.*

*  Input file "app.config" is newer than output file "bin\Debug\CSApplicationSettings.exe.config".*

*  Task "Copy"*

*    Copying file from "app.config" to "bin\Debug\CSApplicationSettings.exe.config".*

*    Command:*

*    copy /y "app.config" "bin\Debug\CSApplicationSettings.exe.config"*

*  Done executing task "Copy".”*

 

Do not copy the app.config if it is older:

“Target "_CopyAppConfigFile" in file "C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets":

*  Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.*

*  Input files: app.config*

*  Output files: bin\Debug\CSApplicationSettings.exe.config”*

 

=======================================================================================

 

Besides, if we want to make sure that each time the applicationName.exe.config is copied and it is not overwritten by app.config, you can set the copy action in the post build commands, e.g. copy /y ..\applicaitonName.exe.config ..\bin\Debug\applicationName.exe.config.   For detail, please see http://msdn.microsoft.com/en-us/library/42x5kfw4.aspx & http://msdn.microsoft.com/en-us/library/aa833213.aspx.

 

If you have any questions regarding this case, please feel free to let me know.

 

Have a nice day!

 

 

Best Regards,
Lingzhi

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Send us any feedback you have about the help from MSFT at [email protected].


Thursday, June 4, 2009 12:57 AM

You may want to check, in the project's properties, the post-build event commands. In the old application you are probably copying the applicationName.exe.Config file after the project is built.

By the way, this seems a kind of odd requirement. May I ask way don't you just use VS default behavior and let him copy the app.config?
Keep it Sharp


Thursday, June 4, 2009 3:29 AM

Thanks Fernando, but the post buld commands of the 2 solutions are identical & just say on successful build. However I had this idea to exclude the app.setting file & see what happened & I found that when I copied items over the settings tage was not properly closed  - the end tage was from the old project..... Now it does as I expect.  As to why I do this - I dont deploy the app.settings file in my application. There may be another way to do this, but this way oddly enough works.andrew


Tuesday, June 9, 2009 1:39 AM

Hi andrew,

 

I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

 

If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

 

Have a nice day!

 

 

Best Regards,
Lingzhi

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Send us any feedback you have about the help from MSFT at [email protected].


Friday, June 12, 2009 12:22 PM

Hi andrew,

 

I am closing this thread and mark some helpful replies as the answers, because you have not followed up with the question.

 

If you have any further questions or concerns, please feel free to contact me or unmark the answers here. 

 

Have a nice day!

 

 

Best Regards,
Lingzhi

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Send us any feedback you have about the help from MSFT at [email protected].