App.Config file in console application C#(控制台应用程序 C# 中的 App.Config 文件)
问题描述
我有一个控制台应用程序,我想在其中写入文件名.
I have a console application in which I want to write the name of a file.
Process.Start("blah.bat");
通常,通过将文件 'blah.bat' 的名称写入 Properties 文件中的 Settings 文件,我会在 Windows 应用程序中拥有类似的东西强>.
但是,在这里我没有找到任何 Settings 文件,我添加了一个 app.config 用于相同目的.
Normally, I would have something like that in windows application by writing the name of the file 'blah.bat' to Settings file in Properties.
However, here I didn't find any Settings file and I added an app.config for the same purpose.
我不确定在 app.config 中写什么,这会导致我实现与 Windows 窗体 中类似的事情.
I am not sure what to write here in app.config, that would lead to me to achieve similar thing as in Windows Forms.
例如:在 Windows 窗体中.Process.Start(Properties.Settings.Default.BatchFile);
其中 BatchFile 是属性设置文件中的字符串.
For eg: In windows forms. Process.Start(Properties.Settings.Default.BatchFile);
where BatchFile is a string in settings file in Properties.
推荐答案
您可以在项目中添加对 System.Configuration 的引用,然后:
You can add a reference to System.Configuration in your project and then:
使用 System.Configuration;
然后
string sValue = ConfigurationManager.AppSettings["BatchFile"];
使用像这样的 app.config 文件:
with an app.config file like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="BatchFile" value="blah.bat" />
</appSettings>
</configuration>
这篇关于控制台应用程序 C# 中的 App.Config 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:控制台应用程序 C# 中的 App.Config 文件
基础教程推荐
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
