[英]How to merge a text file and embed it in C# code build
I create a class library and added a text file as one of the resource for the project.我创建了一个 class 库并添加了一个文本文件作为项目的资源之一。 I use it like this:我这样使用它:
string commandFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"data\vaCommands.txt");
When i release this dll i do not want this text file (data\vaCommands.txt) to be visible for users.当我发布此 dll 时,我不希望此文本文件 (data\vaCommands.txt) 对用户可见。 Is there a way to compile it to the code?有没有办法把它编译成代码? What is the best approach in these situations?在这些情况下最好的方法是什么?
try this:尝试这个:
Add file to Resources.resx
Open up the Resources.resx
file, use the dropdown box to add the file, set Access Modifier
to public
.将文件添加到Resources.resx
打开Resources.resx
文件,使用下拉框添加文件,将Access Modifier
设置为public
。
then you can get text if file like that:然后你可以得到这样的文件:
string text = Properties.Resources.vaCommands;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.