How do I compile my App.config into my exe in a VS2010 C# console app?

前端 未结 10 1934
傲寒
傲寒 2020-12-05 17:24

I\'m creating a console app in Visual Studio 2010 with c#. I want this app to be stand alone, in that all you need is the exe, and you can run it from anywhere. I also want

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 18:03

    I can see where you are going with this, but the answer might be a bit more complicated than you were looking for.

    1. Make app.config to be an embedded resource.
    2. Manually parse the app.config to get default app settings / connection strings / etc
    3. Still look for an app.config and override the defaults you read in earlier with the app.config values

    This way you have some reasonable defaults that you don't have to maintain separate from you app.config as constants, you can run your app as just an exe, and you can still modify it at runtime by adding back in the app.config.

    The one thing to remember, is that reading in the app.config from a resource won't give you the same behavior as the normal app.config. You are basically reading it in and using it by hand.

提交回复
热议问题