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). How would you embed a text file into an exe using only notepad and csc.exe?
-
You are aware that MS offers a free version of VS 2012, right? http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-windows-desktop#product-express-desktop – Mark Kram May 10 '13 at 00:32
2 Answers
According to this website: building embedded resources using csc
Using this KB article and the docs for vs.net's csharp compiler options I arrived at this:
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. 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.

- 2,784
- 2
- 31
- 44
-
Is there a way to do this when compiling from within another program using the CSharpCodeProvider? – Bob May 10 '13 at 01:01
-
You should be able to add the "/res:" parameter in any environment but I'm unfamiliar with the CSharpCodeProvider. – Chief Wiggum May 10 '13 at 01:06
-
-
Cool, is there not Parameter Class or something similar that you can use when calling the compiler? How about this solution? http://stackoverflow.com/questions/826398/is-it-possible-to-dynamically-compile-and-execute-c-sharp-code-fragments – Chief Wiggum May 10 '13 at 02:08
Looking at the help for csc.exe shows that it supports an option /resource:<resinfo>
or /res
for short.
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
Apparently resinfo
means relative\path\to\FileName,ResourceName
.

- 27,142
- 5
- 87
- 100