繁体   English   中英

如何合并文本文件并将其嵌入到 C# 代码构建中

[英]How to merge a text file and embed it in C# code build

我创建了一个 class 库并添加了一个文本文件作为项目的资源之一。 我这样使用它:

    string commandFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"data\vaCommands.txt");

当我发布此 dll 时,我不希望此文本文件 (data\vaCommands.txt) 对用户可见。 有没有办法把它编译成代码? 在这些情况下最好的方法是什么?

尝试这个:

将文件添加到Resources.resx打开Resources.resx文件,使用下拉框添加文件,将Access Modifier设置为public 在此处输入图像描述

然后你可以得到这样的文件:

string text = Properties.Resources.vaCommands;

暂无
暂无

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

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