windows窗体应用程序_如何将配置文件添加到Windows窗体应用程序

在创建Windows Forms应用时,配置文件的添加可能不直观。应用的配置文件应命名为.exe.config,与应用在同一目录下。通过在项目中添加名为App.config的新配置文件,Visual Studio会在构建时自动复制并重命名,避免被覆盖。更改输出文件名时,Visual Studio会自动生成正确的配置文件名。
摘要由CSDN通过智能技术生成
windows窗体应用程序

windows窗体应用程序

When you are creating a new Windows Forms application, it isn’t immediately obvious how to get a configuration file for your application. Your application configuration file is supposed to be called executablename.exe.config, and should be in the same directory as your application in order for the .NET framework to automatically use it.

当您创建新的Windows Forms应用程序时,如何为应用程序获取配置文件并不是很明显。 您的应用程序配置文件应该称为可执行文件名.exe.config,并且应与应用程序位于同一目录中,以便.NET Framework自动使用它。

But when you create the configuration file in the \bin\debug directory, it gets overwritten immediately when you do a new build. That’s slightly annoying.

但是,当您在\ bin \ debug目录中创建配置文件时,在执行新的构建时它将立即被覆盖。 有点烦人。

The proper way to add this file is to add new new configuration file called App.config to your project, which Visual Studio will automatically copy and rename to the same name as your executable’s name when you do a build.

添加此文件的正确方法是将新的名为App.config的新配置文件添加到您的项目中,Visual Studio将在执行构建时自动将其复制并重命名为与可执行文件的名称相同的名称。

There’s a really simple way to do this.. simply go to the File \ Add New Item menu, or hit Ctrl+Shift+A

有一种非常简单的方法来执行此操作。只需转到“文件” \“添加新项”菜单,或按Ctrl + Shift + A

You’ll notice that it’s already set to App.config for you. Just hit the Open button.

您会注意到它已经为您设置为App.config。 只需点击“打开”按钮。

If you look in the Solution Explorer, you will see that the config file is in your project:

如果您在解决方案资源管理器中查看,则会看到配置文件在您的项目中:

 Now build your application, and take a look in the \bin\debug\ folder. You’ll see that the configuration file has automatically been generated and named correctly for your executable:

现在构建您的应用程序,并查看\ bin \ debug \文件夹。 您会看到配置文件已自动生成并为可执行文件正确命名:

If you change the name of the outputted file, Visual Studio is smart enough to generate the new filename correctly.

如果更改输出文件的名称,则Visual Studio足够聪明,可以正确生成新文件名。

Enjoy Configuring!

享受配置!

翻译自: https://www.howtogeek.com/howto/programming/how-to-add-a-configuration-file-to-your-windows-forms-application/

windows窗体应用程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值