how to use CompileAssemblyFromSource to generate windows gui exe

S

sotto

I'm trying to compile some source from within in my c# 2.0 application.

all works fine, but it always generates a windows console executable instead
of a windows gui app.
When i take a look with ildasm at the generated exe it says
..subsystem 0x0003 // WINDOWS_CUI
but i want it to be
..subsystem 0x0002 // WINDOWS_GUI

how can i tell the csharpcodeprovider to build a gui app?
 
G

Guest

I read your post and was kind of curious, so I decided to see what I could
learn.

I hit up the .Net Reflector, and looked at where the CompilerParameters were
converted to the command line args in
Microsoft.CSharp.CSharpCodeGenerator.CmdArgsFromParameters It appears that
it looks at the CommandParameter's GenerateExecutable, and either does /t:exe
or /t:library It doesn't appear there's a way to make it do /t:winexe,
which is what you are looking for.

I dislike any of the solutions I come up with; hopefully others will have a
better solution. The only thought I can come up with is to do something
highly ugly like reflect the whole Microsoft.CSharp namespace and change that
line.... ICK! Look up .Net Reflector by lutz roeder and File Dissassember
attachment for it, if you get that desperate, it may be the lesser of two
evils of writing it all from scratch.

CSharpCodeGenerator, etc. are all internal classes, so you can't inherit
from them, the other option would be to use reflection to call the internal
methods, but none of options sound really good.

Perhaps there's some way you can re-open the assembly, disassemble it, then
resave it with that flag changed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top