Clearly C# / .NET is missing all the purity of a proper programming language – when has any developer sat down with an editor and a terminal and made something with it?
Well, I am currently trying (it’s an open source app and I want it to build from a batch file without needing a proprietory IDE) and it’s hard.
The particular thing that irritated me today was embedding an ICO file into an assembly as a resource. I tried plain old
csc /resource:subdir/file.ico
I tried
resgen subdir/file.ico subdir/file.ico.resource
BUT NO, you can NOT has cheeseburger (said the compiler to the lolcat). I finally solved the issue by realising the following:
- you need to embed the item at compile time
- you need to extract it at runtime using an identifier
- you need to specify the identifier when you embed at compile time.
Great Scott!! so, in build.bat:
csc [snip] /res:subdir/file.ico,app.file.ico [snip]
This embeds the resource with identifier "app.file.ico"
. In your application when you want to create an Icon instance from the file:
Icon i = new Icon(this.GetType().Assembly
.GetManifestResourceStream("app.file.ico"));
There didn’t seem to be a clear answer on the subject on Google, so here you go internets! 🙂
(by the way this is using .NET 2.0, the standard SDK.)