Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I've been working on a project using CodeDom. Generating the code is working fine, what I'm having trouble with is the entry point.

I want to start a form, and I set up the entry point like so:

VB
Dim start As New CodeEntryPointMethod()

Dim codeexp As New CodeSnippetStatement("Dim f As New Form")
start.Statements.Add(codeexp)
codeexp = New CodeSnippetStatement("f.showdialog()")
start.Statements.Add(codeexp)

vClass.Members.Add(start)


For some reason, when I run the generated application, it creates a console along with a form. Could anyone please tell me the reason it does this, and how I can turn off the visible console? I just want to launch the form at the start of the application.

It's probably something simple I'm missing, but after pulling my hair out all day I thought it might be a good idea to get pointed in the right direction. :)
Posted
Comments
Sergey Alexandrovich Kryukov 18-Sep-11 19:18pm    
How much remaining hair do you have? If you pull them on each problem like this one (relatively simple), the suppliers won't last long... :-)
--SA

1 solution

This is just one of the compilation options. Creating a console is just an optional but not alternative to the Windows Application. There are two options in both C# and VB.NET compilers: "/target:winexe" or "/target:exe". The first one does not really instruct a compiler about anything related to Windows application (how could it possibly do it? there is no such thing as "windows", there are System.Windows.Forms, WPF and could be anything else). It simply says "do not create a default console". And the second option enables the console. Probably you got it by default.

So, one real problem is not quite clear terminology used by Microsoft in compilation options.

You need to use the first option using the string property System.CodeDom.Compiler.CompilerParameters. CompilerOptions, see http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.aspx[^].

—SA
 
Share this answer
 
v3
Comments
Bert Mitton 18-Sep-11 20:13pm    
This worked perfectly. You really did hit it on the head with the documentation thing. I'm having a really difficult time finding good, comprehensive documentation of how the codedom works. I've gotten down the namespaces, classes, etc, but trying to find details for things like the parameters is a real bear.

Thanks again for your help, it was exactly what I needed. +5
Sergey Alexandrovich Kryukov 18-Sep-11 20:26pm    
You're very welcome and thank you.

I was pretty much sure it will work, but thank you for testing it so fast and reporting the results back. Yes, this part of .NET libraries is documented much less then others, but I meant terminology problem which also got into Visual Studio IDE UI and confused many developers, so I had to explain how to use console several times even with no relation to Code DOM.

As to Code DOM, it just needs just some practice. Sometimes you have "not implemented" exception with very informative message :-) Too bad, one important not implemented feature is System.CodeDom.Compiler.CodeDomProvider.Parse (with all providers I know). This is probably because instead of developing fundamental CodeDomProvider code and using it in compilers, Microsoft simply runs existing compilers as applications. To check this up, try to delete/rename a compiler application csc.exe or vbc.exe and try to compile with CodeDOM. And the compilers do not expose the parsing and other important features. That's a pity, because parsing of the code would be a very powerful weapon, good to create static code analysis tools, developments tools, IDEs and more...

Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900