简体   繁体   English

如何在C#类库项目(VS2012)中嵌入和使用.txt文件作为资源?

[英]How can I embed and use a .txt file as resource in a C# Class Library Project (VS2012)?

I have looked for quite a bit but I haven't found a solution to this seemingly easy problem. 我已经寻找了很多,但我还没有找到解决这个看似简单的问题的方法。

I am able to add a TXT (CSV) file named "CSVData.txt" as resource in a Console Application project and access it using the namespace easily - it's named "CSVData" in the project. 我能够在控制台应用程序项目中添加名为“CSVData.txt”的TXT(CSV)文件作为资源,并使用命名空间轻松访问它 - 它在项目中命名为“CSVData”。

  string Temp = Properties.Resources.CSVData;

But when I create a Class Library project, I cannot: apparently there's nothing in the namespace "Properties.Resources", even though it is created successfully just as in the Console Application project. 但是当我创建一个类库项目时,我不能:显然命名空间“Properties.Resources”中没有任何内容,即使它是在Console应用程序项目中成功创建的。

Tested multiple times with fresh projects with the same results. 使用具有相同结果的新项目多次测试。

I'm sure it's something very, very simple, but I can't for the life of me figure this one out. 我确信这是非常非常简单的事情,但我不能为我的生活想出这个。

Most probably the problem is, that the access modifier for the resource file is default = internal, which means it is visible only inside of the dll. 最有可能的问题是,资源文件的访问修饰符是default = internal,这意味着它只在dll内部可见。 Go to the resources page and try to change it to Public: 转到资源页面并尝试将其更改为Public:

在此输入图像描述

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

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