简体   繁体   English

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

[英]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.

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