C# VS2013 如何在发布后在控制台应用程序中使用 App.config

C# VS2013 How to use App.config in a console application after publish it

我有一个带有 App.Config 和一些键的控制台应用程序。将使用此应用程序的用户需要在 运行 之前更改某些键的值。

如果发布我的应用程序,我在安装后看不到 App.Config。如何添加此功能?

谢谢。

当您发布应用程序时,app.config 会转换为 exe.config。打开该文件并进行编辑。

如果您通过单击安装程序安装此程序,找到文件的最简单方法是 运行 应用程序,打开任务管理器 (CTRL-SHIFT-ESC),select应用程序并右键单击|打开文件位置。然后您应该在同一文件夹中找到 *.exe.config 文件。

这应该有助于您的理解:

https://msdn.microsoft.com/en-us/library/ms228995.aspx

具体来说:"In a Windows Forms applications (iterchangeable with console in this instance) not deployed using ClickOnce, an application's app.exe.config file is stored in the application directory, while the user.config file is stored in the user's Documents and Settings folder. In a ClickOnce application, app.exe.config lives in the application directory inside of the ClickOnce application cache, and user.config lives in the ClickOnce data directory for that application."

帮助的简短版本:查看这些子文件夹之一 post deploy 如果您使用的是 clickonce 发布选项 - C:\Users\UsersNameGosHere\AppData\Local\Apps.0

除了让你起床和 运行 在这里和现在,如果你有特定的用户指定值在部署后需要 mod,那么你真的应该考虑将它们放入用户设置而不是应用程序设置中。