如何在 VS2010 C# 控制台应用程序中将我的 App.config 编译成我的 exe? [英] How do I compile my App.config into my exe in a VS2010 C# console app?

查看:22
本文介绍了如何在 VS2010 C# 控制台应用程序中将我的 App.config 编译成我的 exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 c# 在 Visual Studio 2010 中创建控制台应用程序.我希望这个应用程序是独立的,因为你需要的只是 exe,你可以从任何地方运行它.我还想使用 app.config 来存储连接字符串等等.

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 to use app.config to store connection strings and so on.

我的问题是我似乎无法弄清楚如何将该 app.config 数据包含到已编译的 exe 中.我确实看到它创建了 appname.exe.config,但我不希望人们在获得应用程序时不必担心获取两个单独的文件.

My problem is that I can't seem to figure out how to include that app.config data into the compiled exe. I do see it creates appname.exe.config, but I don't want people to have to worry about grabbing two separate files when they get the app.

我所做的所有谷歌搜索都没有找到任何结果.这甚至可能吗?

None of the googling I've done has come up with anything. Is this even possible?

推荐答案

你不能.此类配置文件的一半在于允许在应用程序本身之外更改应用程序的配置.

You can't. Half the point of such config files is to allow changes to the configuration of the app outside of the app itself.

您只需修改您的程序,使其不依赖于应用配置文件——最简单的方法是将配置中的值粘贴到只读全局变量中.

You would simply have to modify your program so that it didn't have a dependency on the app config file -- easiest way to do that would be to just stick the values inside your config into read only global variables.

这篇关于如何在 VS2010 C# 控制台应用程序中将我的 App.config 编译成我的 exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆