简体   繁体   中英

c# class library use files

I'm building a class library which use a .dat file, inside the library i made a folder App_Data and put the .dat file inside it, how can i have my library to use the .dat file. How could it be included at the dll when build?

I already tried Path.GetFullPath , and almost anything in Path, but all i get is the path to debug folder, and in that folder i dont even have the .dat file which i expect to be included because the .dat file is in the project.

I just want to use that .dat file without hard coding its path, and it should still work when referenced.

You must right-click the .dat file and set Copy to Output Directory = Copy Always . Doing so, the path to the debug folder will correctly point to the file. No need to hard code the path.

在此输入图像描述

If you're interested in embedding the .dat file in the DLL (a bit more work), you can go this way:

Can I embed other files in a DLL?

  1. right-click the file and select Properties
  2. set Copy to Output Directory = Copy Always
  3. not change other properties (for example Build Action, ...)

将文件添加到输出文件夹

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