且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#:以编程方式将资源文件添加到特定文件夹

更新时间:2023-09-17 15:45:22

有几种方法可以做到这一点。我描述的是我是如何做的那样。



退出Visual Studio并使用非VS编辑器(例如记事本)编辑xx.csxproj文件。在代码中找到文件引用,只需将任何额外的目录结构添加到filespec中。小心在需要时加倍反斜杠(\\)。如果您愿意,可以将相对目录名称更改为绝对。不要忘记为所有配置执行此操作(例如,调试,发布,...)。



[免责声明:我经常为C ++做这类事情项目文件;希望我已将此正确翻译成C#lingo。]



[更新1]

首先在您的位置创建资源文件选择。将文件添加到项目中。根据文件/文件夹的存在位置,VS将对其进行相对或绝对引用。
There are several ways to do this. What I describe is how I do that kind of thing.

Exit Visual Studio and edit the xx.csxproj file with a non-VS editor (eg. Notepad). Find the file reference in the code and simply add any extra directory structure to the filespec. Be careful to double up backslashes ("\\") where required. You can change relative directory names to absolute if you like. Don't forget to do this for all configurations (eg. Debug, Release, ...).

[disclaimer: I do this type of thing frequently for C++ project files; hopefully I have translated this correctly into C# lingo.]

[Update 1]
Create the resource file first, in the location of your choice. Add the file to the project. Depending on where the file/folder exists, VS will make either a relative or absolute reference to it.