compile problems

M

Mike

I have created a solution with 3 projects, P1, P2, P3.
Project P1 has my main method and it also relies on
objects/classes from P2 and P3. Two Questions:

1.
P2 and P3 don't have main methods. Do they need main
methods even though some of their objects are only being
created in P1? The reason I'm asking is because I get
compile errors for both projects which says that
the .exes don't have entry points.

2.
When I try to instantiate P2 and P3 objects in P1, I get
compile errors which tell me that I'm missing using
statements or assembly references. I tried 'using'
statements but it still didn't work. I assume I need to
create .dlls from P2 and P3 and then add references to
P1. Is this the right assumption? Do I need to use
command line or can I do it through the GUI? Does anyone
have any useful links to reading material on this kind of
stuff?

Any suggestions will be greatly appreciated. Thanks a lot
for the reply.

Mike
 
J

Jon Skeet

Mike said:
I have created a solution with 3 projects, P1, P2, P3.
Project P1 has my main method and it also relies on
objects/classes from P2 and P3. Two Questions:

<snip>

Both of your problems are basically due to P2 and P3 having their
project types as application (console or windows). Instead, they should
be "Class Library". You then need to add a reference to each of P2 and
P3 in P1 - in P1, there's an item "References". Right click that and
click on "Add Reference". Go to the Projects tab and click on each of
P2 and P3 to add them as references.
 
R

Ranier Dunno

-----Original Message-----
I have created a solution with 3 projects, P1, P2, P3.
Project P1 has my main method and it also relies on
objects/classes from P2 and P3. Two Questions:

1.
P2 and P3 don't have main methods. Do they need main
methods even though some of their objects are only being
created in P1? The reason I'm asking is because I get
compile errors for both projects which says that
the .exes don't have entry points.

If P2 and/or P3 should be standalone executables (exe's),
they need entry points. If they will only be used from
other projects (like P1), they should be compiled as
libraries (dll's) instead. Right-click on your projects
in VS .NET and choose properties -> output type.
2.
When I try to instantiate P2 and P3 objects in P1, I get
compile errors which tell me that I'm missing using
statements or assembly references. I tried 'using'
statements but it still didn't work. I assume I need to
create .dlls from P2 and P3 and then add references to
P1. Is this the right assumption? Do I need to use
command line or can I do it through the GUI? Does anyone
have any useful links to reading material on this kind of
stuff?

This is the right assumption. Once you have compiled P2
and P3 as DLL's, you can include references to them
easily using the VS .NET GUI. Right-click on 'References'
under P1, choose 'Add reference', then 'Projects' and
browse until you find your DLL's.

- Ranier
 
M

Mike

-----Original Message-----


<snip>

Both of your problems are basically due to P2 and P3 having their
project types as application (console or windows). Instead, they should
be "Class Library". You then need to add a reference to each of P2 and
P3 in P1 - in P1, there's an item "References". Right click that and
click on "Add Reference". Go to the Projects tab and click on each of
P2 and P3 to add them as references.

--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
.

Thanks for the reply. It was very helpful. I have one
more question. I added a project P4 to my solution which
is a standalone, thus it(P4) has a main method. I get
the same referencing compile error even though I tried
including a 'using' statement. How can I add P4 as a
reference in order to use its objects/classes in P1 even
though they both have main methods? Again thank you for
the reply.
 
J

Jon Skeet

Mike said:
Thanks for the reply. It was very helpful. I have one
more question. I added a project P4 to my solution which
is a standalone, thus it(P4) has a main method. I get
the same referencing compile error even though I tried
including a 'using' statement. How can I add P4 as a
reference in order to use its objects/classes in P1 even
though they both have main methods? Again thank you for
the reply.

I don't believe you can add a reference to an executable in VS.NET.
 
C

Chris Capel

Try putting all your main code in P4 into a separate .dll, then writing a
new Windows Executable that simply creates a form from P4.dll. The entire
code of the executable could look like this:

using System;
using System.Windows.Forms
using P4Namespace;

class SomeClass {
static void Main() {
Application.Run(new P4FormClass());
}
}

Not much more than that would be necessary, and then you could reference P4
from P1 or wherever else.

Chris
 

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