如何在C#项目中嵌入的app.config? [英] How do you embed app.config in C# projects?

查看:474
本文介绍了如何在C#项目中嵌入的app.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您编译C#项目,从app.config中的应用程序设置与exe文件一起保存。例如,如果该计划名称为solve_np.exe,会有一个solve_np.exe.config旁边,使它看起来不那么整齐,比我想它。你怎么能嵌入到.exe文件?

When you compile a C# project, the app settings from app.config are saved along with the exe file. For example, if the program name is "solve_np.exe", there will be a "solve_np.exe.config" next to it, making it look less neat than I want it to. How can you embed it into the .exe?

我试图设置生成操作为嵌入资源,但没有做的伎俩。

I tried to set Build Action to Embed Resource, but that did not do the trick.

推荐答案

啊哈。我猜你跌倒的Visual Studio将自动臭的东西在你不想最终用户配置的配置。

Aha. I guess you're falling foul of Visual Studio automatically placing stuff in configuration that you DONT want configured by the end user.

在这种情况下,利用资源。只需添加类型的.resx的新文件。有了这个,你就可以添加一些东西像字符串和图像资源文件。你建立这之后它应该提供的资源静态访问(它通常会产生从你的资源$ C ​​$ C文件,所以您不必访问的ResourceManager自己)。

In this case use resources. Simply add a new file of type .resx. With this you'll be able to add things like strings and images to the resource file. After you build this it should provide static access to the resources (it typically generates a code file from the resources for you so you don't have to access ResourceManager yourself).

例如。如果我有一个生成后调用MyConfigValue串制成resources.resx我应该能够访问此类似:

E.G. If I made resources.resx with a string called MyConfigValue after a build I should be able to access this like:

textBox.Text = Resources.MyConfigValue;

如果您想获得有点不同的,但不应该是可配置的值,那么这是把它们放在正确的地方。

If you want values that are kinda variable but shouldn't be configurable then this is the right place to put them.

心连心。

这篇关于如何在C#项目中嵌入的app.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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