简体   繁体   English

C#控制台应用程序不断创建配置文件

[英]C# Console application keeps creating a Configuration FIle

I am new to C#. 我是C#的新手。 I am an admin, not a programmer, but I am starting to see how being able to write some console apps could help me with automation. 我是管理员,而不是程序员,但我开始看到能够编写一些控制台应用程序可以如何帮助我实现自动化。 So I wrote one and it works well. 所以我写了一个,它很好用。

Here is the issue. 这是问题。 Every time I execute the exe file for the console application, it generates a .config file. 每次我为控制台应用程序执行exe文件时,它都会生成一个.config文件。 There isn't really anything in the config file. 配置文件中实际上没有任何内容。 just a few lines. 仅几行。 How do I make it stop. 我如何使其停止。 The Program.cs is really just calling SCOM's SDK to put a machine into maintenance mode. Program.cs实际上只是在调用SCOM的SDK来使计算机进入维护模式。

Developed in: c# in visual studio 2013 .net version used - 3.5 开发于:Visual Studio 2013 .net版本中的C#使用-3.5

It's not entirely clear what you're asking. 您要问的还不清楚。 But assuming commenter Jon's guess is correct, and that you really mean that when you build your executable, a .config file is generated, then his advice is correct: just remove the "App.config" file from your project, and no .config file will be generated. 不过,假设评论员乔恩的猜测是正确的,那你真的是,当你建立你的可执行文件,生成config文件,那么他的建议是正确的:只是从你的项目中删除“的App.config”的文件,并没有的.config文件将被生成。 The "App.config" file is the template for the .config file; “ App.config”文件是.config文件的模板; at build time, the file is copied to the output directly, using the executable name and the extension .config. 在构建时,使用可执行文件名称和扩展名.config将文件直接复制到输出中。

Please note that this may or may not be safe to do. 请注意,这样做可能会或可能不会安全。 It probably is. 可能是。 However, some C# projects have configuration information in the .config file that is actually needed. 但是,某些C#项目在实际需要的.config文件中具有配置信息。 Please see Is app.config required in .Net 4.0 C# projects? 请参阅.Net 4.0 C#项目中是否需要app.config? for more details on that question. 有关该问题的更多详细信息。

Finally, I will suggest that for simple automation tasks, you may find other tools more appropriate that even a simple C# console program. 最后,我建议对于简单的自动化任务,您可能会发现比简单的C#控制台程序更合适的其他工具。 The two I use most commonly are PowerShell and plain old batch files, though there are a number of other similar scripting-style automation tools that work on Windows (including a variety of *nix-style shells that are compiled for Windows). 我最常用的两个是PowerShell和普通的旧批处理文件,尽管还有许多其他类似的脚本样式自动化工具可在Windows上运行(包括为Windows编译的各种* nix样式外壳)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM