[英]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.我正在构建一个使用.dat
文件的 class 库,在库中我创建了一个文件夹App_Data
并将.dat
文件放入其中,我怎样才能让我的库使用.dat
文件。 How could it be included at the dll when build?构建时如何将其包含在 dll 中?
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.我已经尝试过Path.GetFullPath
和 Path 中的几乎所有内容,但我得到的只是调试文件夹的路径,在该文件夹中我什至没有我希望包含的.dat
文件,因为.dat
文件位于项目。
I just want to use that .dat
file without hard coding its path, and it should still work when referenced.我只想使用那个.dat
文件而不对其路径进行硬编码,并且在引用时它应该仍然有效。
You must right-click the .dat
file and set Copy to Output Directory
= Copy Always
. 您必须右键单击.dat
文件并将“ 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: 如果您对将.dat
文件嵌入DLL
感兴趣(稍微多一些工作),可以这样做:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.