简体   繁体   English

在没有Visual Studio的C#中嵌入资源

[英]Embedding Resource in C# without Visual Studio

I have a question similar to this . 我有一个与此类似的问题。 However, I am not using Visual Studio (yeah, I know I should but I don't want to, so don't just say use Visual Studio). 但是,我没有使用Visual Studio(是的,我知道我应该,但我不想这么做,所以不要只是说使用Visual Studio)。 How would you embed a text file into an exe using only notepad and csc.exe? 您将如何仅使用记事本和csc.exe将文本文件嵌入exe?

According to this website: building embedded resources using csc 根据此网站: 使用csc构建嵌入式资源

Using this KB article and the docs for vs.net's csharp compiler options I arrived at this: 使用这篇知识库文章vs.net的csharp编译器选项的文档,我得出以下结论

csc.exe /out:Resources.dll /target:library /res:image.png,Resources.image.png Resources.cs

The tricky thing here is that the ms docs for the /res option only mention using it with .resources files, which are compiled resx files. 此处棘手的事情是/ res选项的ms docs仅提及将其与.resources文件(已编译的resx文件)一起使用。 But in fact you can embed any sort of file in there. 但是实际上,您可以在其中嵌入任何类型的文件。 The "Resources.image.png" part identifies the resource and puts it under the Resources namespace, which is what vs.net will do when specify a default namespace for the project. “ Resources.image.png”部分标识资源并将其放置在Resources命名空间下,这是vs.net在为项目指定默认命名空间时将执行的操作。

Looking at the help for csc.exe shows that it supports an option /resource:<resinfo> or /res for short. 查看csc.exe的帮助表明它支持选项/resource:<resinfo>或简称为/res

Looking at the build output from a project in VS that has an embedded resource shows that it uses this as well: /resource:TextFile1.txt,ConsoleApplication2.TextFile1.txt 查看VS中具有嵌入式资源的项目的生成输出,该显示也将使用它:/resource: /resource:TextFile1.txt,ConsoleApplication2.TextFile1.txt

Apparently resinfo means relative\\path\\to\\FileName,ResourceName . 显然resinfo表示relative\\path\\to\\FileName,ResourceName

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

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