简体   繁体   中英

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.

  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.

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. Go to the resources page and try to change it to Public:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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