Is it possible to have two Main() in one solution?

G

Guest

Hi,

I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.

Is is possible to do this? If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?

I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.

Thanks,
 
G

Guest

Sorry I didn't mean to run B.exe by using Process.Start.
I mean how to call Project B: Application.Run() in Project A.

thanks.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You cannot.

You have a solution with two separate executables. They live endependently
one of the other. If you want to start running an instance of one from the
other you have to use Process.Start.


Otherwise, why you want to run B.App_Run ?
 
G

Guest

I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.
Is is possible to do this?

Of course, that's the point of having "solutions"; grouping several EXEs and
DLLs together and managing their relationships.
If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?

I don't see why you would want to, but see below if you do. What is it
you're trying to achieve? You probably don't even want to have two EXEs, if
the goal is perhaps A has a main form and B has a dialog that A needs to
pop-up, then B should be in a DLL rather than an EXE (it can still be its own
project if you like, I have some dialogs that I use with several forms) form
A would then instantiate and show it, there is no need to call a Main to show
the dialog.
I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.

Of course you can, an EXE is an assembly.

-----

I did it with console EXEs, but it ought to work with WinForms as well.

1) Make sure the class for B is public and its Main is public
2) Add a reference to project B to project A
3) In A, use: classB.Main ( args ) ;
 
G

Guest

Thanks PIEBALD.

Now I can call B.Main(). But I need to change the output type to Class
Library otherwise I can't add a reference.
 
G

Guest

Now I can call B.Main(). But I need to change the output type to Class
Library otherwise I can't add a reference.

No you don't. You can add a reference to an assembly that's in an EXE.
 
J

james.curran

No you don't. You can add a reference to an assembly that's in an EXE.

I believe what he is saying is that the Right-Click "Add reference"
feature on Visual Studio will refuse to add the reference until the
assembly has a DLL extension.
 
G

Guest

I believe what he is saying is that the Right-Click "Add reference"
feature on Visual Studio will refuse to add the reference until the
assembly has a DLL extension.

The EXE projects in my solution show up as available for reference from the
other projects.
 
W

William Stacey [MVP]

I think that is a 2.0 feature IIRC.

--
William Stacey [MVP]

|> I believe what he is saying is that the Right-Click "Add reference"
| > feature on Visual Studio will refuse to add the reference until the
| > assembly has a DLL extension.
|
| The EXE projects in my solution show up as available for reference from
the
| other projects.
 
J

Jon Skeet [C# MVP]

William Stacey said:
I think that is a 2.0 feature IIRC.

Well, it's a Visual Studio 2005 feature. Even in .NET 1.1 you can get
the command-line compiler to add a reference to an executable, but to
get it to work in VS.NET 2003 you have to hack the project file a bit.
 
J

james.curran

The EXE projects in my solution show up as available for reference from the other projects. <<<

But if you try adding it (in VS2003), it will give an error.
 

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