Multiple projects in one C# solution

  • Thread starter Jon via DotNetMonster.com
  • Start date
J

Jon via DotNetMonster.com

Hi all

I'm creating a Contact Management System. I have added one console project
and various window projects (for the user interfaces) to the solution.
I've added these as obviously there will multiple GUI's and I want to store
all the generic classes in the console project I've added.
Firstly, is this how you are meant to go about things to achieve my above
thinking/aim?

Secondly, in a window project's Button_Click event how do I create an
object of a class that is stored in the console project? - How do I fully
qualify it? - i.e. ConsoleName.NamespaceName.ClassName temp = new
ConsoleName.NamespaceName.ClassName();

Does anybody know of any links that explain would the above to me as my C#
books do not explain this?

Any help would be very much appreciated.
Jon (A newcomer to C#).
 
D

Dmitry Rutcovsky

Hello, Jon!

JvD> Hi all

JvD> I'm creating a Contact Management System. I have added one console
JvD> project and various window projects (for the user interfaces) to the
JvD> solution. I've added these as obviously there will multiple GUI's and
JvD> I want to store all the generic classes in the console project I've
JvD> added. Firstly, is this how you are meant to go about things to
JvD> achieve my above thinking/aim?

You should create Class Library project to store all functionality.
After that you can use classes from this project in other, by doing sme
steps;
- add reference to this project (in AddReference Dialog choose Projects
tab) and add reference to class library project
- you can use all functionality from this library by full name
YouLibraryNamespace.YourClass
or with directive using (using YouLibraryNamespace; ..... /*somewhere in
code*/ YourClass youClass = new YourClass();)

- if you need use this functionality in console project, the steps will be
the same.

JvD> Secondly, in a window project's Button_Click event how do I create an
JvD> object of a class that is stored in the console project? - How do I
JvD> fully qualify it? - i.e. ConsoleName.NamespaceName.ClassName temp =
JvD> new ConsoleName.NamespaceName.ClassName();

see above

JvD> Does anybody know of any links that explain would the above to me as
JvD> my C# books do not explain this?

msdn.microsoft.com :)

JvD> Any help would be very much appreciated.
JvD> Jon (A newcomer to C#).

JvD> --
JvD> Message posted via http://www.dotnetmonster.com

With best regards, Dmitry Rutcovsky. E-mail: (e-mail address removed)
 
B

Bob Powell [MVP]

It sounds as though what you want to do is create a DLL project that's used
by the other projects in the solution.

Create a class library project for your utility classes and then ad a
reference to that project in an GUI projects in the same solution.

A console application is the wrong choice but I'm sure you can shift the
utilities to a DLL class library with minimal problems.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
J

Jon via DotNetMonster.com

Hi Bob, Thanks for your advice too.

This is to both you and Dmitry. Is a class library the normal place where
all the application core classes are stored, and not to be stored in the
form or console files themselves?

Thanks very much, Jon.
 
B

Bob Powell [MVP]

A console application isn't a good place to try and keep utility classes. A
DLL is ideal and in fact is designed for just that case. Your class library
DLL can be accessed and shared by several applications at once. For
application core classes you might take an architectural descision to
maintain them in the application if the app wwas stand-alone but if you have
several "front-ends" for a suite of applications sharing common
functionality then you'd definitely keep it in a DLL.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
J

Joanna Carter \(TeamB\)

Secondly, in a window project's Button_Click event how do I create an
object of a class that is stored in the console project? - How do I fully
qualify it? - i.e. ConsoleName.NamespaceName.ClassName temp = new
ConsoleName.NamespaceName.ClassName();

If you are only using the console project to create classes for use in other
UI projects then you need to change this to a class library rather than an
executable project.

Once you have doen this, then simply add the library project to the
references of the UI projects and to the 'using' statements of the modules
that need the classes. Then you don't need to fully qualify the classes when
you use them.

Joanna
 

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