如何嵌入在.NET程序集的文本文件? [英] How to embed a text file in a .NET assembly?

查看:117
本文介绍了如何嵌入在.NET程序集的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想嵌入一个文本文件中的一个组件,这样我就可以加载文本,而不必从磁盘读取它,使我需要的一切都包含在exe文件中。 (所以它更便携)

I would like to embed a text file in an assembly so that I can load the text without having to read it from disk, and so that everything I need is contained within the exe. (So that it's more portable)

有没有办法做到这一点?我认为一些与资源文件?

Is there a way to do this? I assume something with the resource files?

如果你能,你怎么做,你怎么programaticaly加载文本转换成字符串?

And if you can, how do you do it and how do you programaticaly load the text into a string?

推荐答案

右键单击该项目文件,选择属性。

Right-click the project file, select Properties.

在打开,转至资源选项卡,如果它在标签页中间的只是一个蓝色的链接窗口,单击它,以创建一个新的资源。

In the window that opens, go to the Resources tab, and if it has just a blue link in the middle of the tab-page, click it, to create a new resource.

然后从上面的标签页的工具栏,选择添加一个新的文本文件,给它一个名称,它会被添加到您的项目,并开辟了。

Then from the toolbar above the tab-page, select to add a new text file, give it a name, it will be added to your project and opened up.

如果你走得很远得到这个,然后在code,你可以输入Resources.TheNameYouGaveTheTextFileHere,您可以访问其内容。请注意,第一次使用的资源类中的一类,你需要添加一个using指令(按Ctrl +打字资源得到菜单让VS来为你做它之后)。

If you get this far, then in your code you can type in Resources.TheNameYouGaveTheTextFileHere and you can access its contents. Note that the first time you use the Resources class in a class, you need to add a using directive (hit Ctrl+. after typing Resources to get the menu to get VS to do it for you).

如果事情是不清楚上面的介绍,请发表评论,我会编辑它,直到它是完整的还是有道理的:)

If something was unclear about the above description, please leave a comment and I'll edit it until it is complete or makes sense :)

这篇关于如何嵌入在.NET程序集的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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