none
App.config location question

    Question

  • I create an app.config in my project. After i compile, i also find the app.config is under \Debug folder.

    I direct run the .exe from \Debug folder,  but I find the config file is useless if i try to change the value inside (i mean the app.config file under \Debug). The changed value cannot affect the running program.

    Do you know how i can let the program use the configuration file which location is under \Debug.

    Thanks!

    Kevin


    Kevin
    Friday, October 21, 2011 6:45 PM

All replies

  • Hi qiyushen,

    The app.config file should in the project directory. (That is, the app.config file should in the same folder with project file.) You can refer to the following article :

    How to: Add Application Configuration Files to C# Projects:

    http://msdn.microsoft.com/en-us/library/ms184658(v=VS.100).aspx

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by lucy-liuModerator Tuesday, November 01, 2011 10:06 AM
    • Unmarked as answer by qiyushen Friday, February 03, 2012 6:13 PM
    Monday, October 24, 2011 6:57 AM
    Moderator
  • Hi qiyushen,

    I temporary make my last reply as answer. You can unmark it if they provide no help

    Thank you for your understanding!

     

    Best regards,

    Lucy

     


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 01, 2011 10:06 AM
    Moderator
  • Dear Lucy,

    i know i can change the app.config file in project folder, but can you tell how can i move it to the executable \Debug folder after compile. Then i can copy the executable folder to user and let them change the setting by themselves.

    Thanks!

    Kevin


    Kevin
    Wednesday, November 02, 2011 1:03 AM
  • Hi qiyushen,

    The app.config file should in the project directory. (That is, the app.config file should in the same folder with project file.) You can refer to the following article :

    How to: Add Application Configuration Files to C# Projects:

    http://msdn.microsoft.com/en-us/library/ms184658(v=VS.100).aspx

     

    Best regards,

    Lucy

    That is quite obviously not the right answer, or maybe it is just not for the question which was asked!

    Do you know the answer, because I also would like to know.

    Thanks

    Friday, February 03, 2012 2:01 PM
  • My answer is to make your own AppSetting-like project. It's a direct way and I just did on this way. It's not that complicated and flexible which fits your own needs...

    Kevin


    Kevin
    Friday, February 03, 2012 6:12 PM
  • True, the narrative the responder wrote is not the right answer, but I looked at the link she gave, and it points to the right answer:

    "When you build your project, the development environment automatically creates a copy of your app.config file, changes its file name so that it has the same file name as your executable, and then moves the new .config file in the bin directory."

    So ... when you build, if your program is named MyCustomApp, the build process will create (in /bin/Debug and/or /bin/Release, whichever you specified) MyCustomApp.exe and MyCustomApp.exe.config. The latter is your project's App.config file, copied into the build directory with the new name.

    That's the config file that will be used if you run MyCustomApp.exe from that directory. If you want to skip the build step, just put your own config file in there and name it MyCustomApp.exe.config.

    I have tested this in Visual Studio 2013.

    Thursday, February 22, 2018 7:30 PM