namespaces, projects and solutions

T

TomC

I know this is long, but please bear with me.

I'm coming from a Java background and trying to get familiar with C#
and Visual Studio for my own benefit. To accomplish that, I have been
doing some experimenting, writing trivial apps to test my
understanding of things.

My latest experiment worked, but NOT in the way that I had
anticipated. I suspect that my question may be as much about VS as it
is about C#. I'll get to the question shortly, but first let me
describe what I have done.

More or less as an intellectual exercise I have created a couple of
trivial applications and gave them the same project name, but
different solution names. The first application was a CONSOLE
application which I gave the highly inventive name
"CircleApplication". I called the solution "CircleDriver".

In this project, I added another class that I called the Circle
class. As the name implies, it merely represents a Circle (I said the
app was trivial) with a couple of instance fields (radius and
unitOfMeasure). Naturally, I created a constructor, a couple of
properties and methods. After I got the Circle class working, I used
Program.cs as a driver to test it and everything worked as expected.

After that, I closed my solution and created a new WINDOWS project. I
also called this one "CircleApplication", so it would be in the same
namespace as the Circle class, but named the solution "CircleGUI". I
added a reference to the Circle class, and used the form to create a
simple GUI where I could enter in the radius and unit of measure, and
output the Circumference and Area. Fired it up, and everything worked
like a charm.

When I added the reference to the Circle class, I expected to see one
folder called CircleApplication representing the namespace, with two
project folders inside it. Instead, I had TWO new folders in my
Projects folder ("CircleDriver" and "CircleGUI"), and EACH had a
folder inside named "CircleApplication". I also noticed that a copy
of Circle.cs had been placed in the folder containing my GUI.

As I see things, if I create a project with ten classes (not counting
the GUI), and I want to test each class individually before creating
the main project, like I did the Circle class, I am going to end up
with ten folders, all containing a folder with the same name as the
namespace.

And then when I create the GUI and tie it all together, I'll end up
with an eleventh folder, also containing a subfolder named to match
the namespace, and VS will copy all of the source code files that I
reference over to this folder.

OK, here comes the question.


Is that the way things are done in C#/Visual Studio?
 
G

Guest

When your create the CircleGUI and CircleDriver projects two different
solutions were created for you. And this is the reason of problem, I suppose.

Generaly there is only one solution for all projects.
I suppose your need to go other way - create the project with the solution
CircleGUI firstly.
And after that create the CircleDriver project *but* use *the same*
CircleGUI solution for your app

It this case you will have the single solution with different projects inside.

Now you may manually move your CircleDriver project to the CircleGUI solution
 
T

TomC

Thanks for the feedback.

Correct me if I am wrong, but it sounds like you are saying that I
should have one project/solution with two namespaces - a "CircleGUI"
namespace, and a "CircleDriver" namespace. And after I use the
CircleDriver to ensure that the Circle class is working properly, I'd
copy and paste that file (Circle.cs) into the CircleGUI namespace and
use it.

If that is correct, will I also have to manually change the identifier
for the namespace in the Circle class from CircleDriver to CircleGUI?
If not, will I run into a problem with the Circle class being
recognized?

Thanks for the info

When your create the CircleGUI and CircleDriver projects two different
solutions were created for you. And this is the reason of problem, I suppose.

Generaly there is only one solution for all projects.
I suppose your need to go other way - create the project with the solution
CircleGUI firstly.
And after that create the CircleDriver project *but* use *the same*
CircleGUI solution for your app

It this case you will have the single solution with different projects inside.

Now you may manually move your CircleDriver project to the CircleGUI solution

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog:http://spaces.live.com/laflour

TomC said:
I know this is long, but please bear with me.
I'm coming from a Java background and trying to get familiar with C#
and Visual Studio for my own benefit. To accomplish that, I have been
doing some experimenting, writing trivial apps to test my
understanding of things.
My latest experiment worked, but NOT in the way that I had
anticipated. I suspect that my question may be as much about VS as it
is about C#. I'll get to the question shortly, but first let me
describe what I have done.
More or less as an intellectual exercise I have created a couple of
trivial applications and gave them the same project name, but
different solution names. The first application was a CONSOLE
application which I gave the highly inventive name
"CircleApplication". I called the solution "CircleDriver".
In this project, I added another class that I called the Circle
class. As the name implies, it merely represents a Circle (I said the
app was trivial) with a couple of instance fields (radius and
unitOfMeasure). Naturally, I created a constructor, a couple of
properties and methods. After I got the Circle class working, I used
Program.cs as a driver to test it and everything worked as expected.
After that, I closed my solution and created a new WINDOWS project. I
also called this one "CircleApplication", so it would be in the same
namespace as the Circle class, but named the solution "CircleGUI". I
added a reference to the Circle class, and used the form to create a
simple GUI where I could enter in the radius and unit of measure, and
output the Circumference and Area. Fired it up, and everything worked
like a charm.
When I added the reference to the Circle class, I expected to see one
folder called CircleApplication representing the namespace, with two
project folders inside it. Instead, I had TWO new folders in my
Projects folder ("CircleDriver" and "CircleGUI"), and EACH had a
folder inside named "CircleApplication". I also noticed that a copy
of Circle.cs had been placed in the folder containing my GUI.
As I see things, if I create a project with ten classes (not counting
the GUI), and I want to test each class individually before creating
the main project, like I did the Circle class, I am going to end up
with ten folders, all containing a folder with the same name as the
namespace.
And then when I create the GUI and tie it all together, I'll end up
with an eleventh folder, also containing a subfolder named to match
the namespace, and VS will copy all of the source code files that I
reference over to this folder.
OK, here comes the question.
Is that the way things are done in C#/Visual Studio?
 
G

Guest

No.

Solution packaging and project packaging are different level of hierarchy
where your projects locates

the uppermost level is the "solution" with is automatically creating for
each new project by default. Solution is just a folder with .sln file where
all other project folders locate

Each project is locates in separate folder, but they should be into the
solution folder

so, u need to have folder hierarchy smth like this
CircleGUI \\ solution folder
+ CircleGUI.sln \\solution file
+ CircleDriver \\ project folder


--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour



TomC said:
Thanks for the feedback.

Correct me if I am wrong, but it sounds like you are saying that I
should have one project/solution with two namespaces - a "CircleGUI"
namespace, and a "CircleDriver" namespace. And after I use the
CircleDriver to ensure that the Circle class is working properly, I'd
copy and paste that file (Circle.cs) into the CircleGUI namespace and
use it.

If that is correct, will I also have to manually change the identifier
for the namespace in the Circle class from CircleDriver to CircleGUI?
If not, will I run into a problem with the Circle class being
recognized?

Thanks for the info

When your create the CircleGUI and CircleDriver projects two different
solutions were created for you. And this is the reason of problem, I suppose.

Generaly there is only one solution for all projects.
I suppose your need to go other way - create the project with the solution
CircleGUI firstly.
And after that create the CircleDriver project *but* use *the same*
CircleGUI solution for your app

It this case you will have the single solution with different projects inside.

Now you may manually move your CircleDriver project to the CircleGUI solution

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog:http://spaces.live.com/laflour

TomC said:
I know this is long, but please bear with me.
I'm coming from a Java background and trying to get familiar with C#
and Visual Studio for my own benefit. To accomplish that, I have been
doing some experimenting, writing trivial apps to test my
understanding of things.
My latest experiment worked, but NOT in the way that I had
anticipated. I suspect that my question may be as much about VS as it
is about C#. I'll get to the question shortly, but first let me
describe what I have done.
More or less as an intellectual exercise I have created a couple of
trivial applications and gave them the same project name, but
different solution names. The first application was a CONSOLE
application which I gave the highly inventive name
"CircleApplication". I called the solution "CircleDriver".
In this project, I added another class that I called the Circle
class. As the name implies, it merely represents a Circle (I said the
app was trivial) with a couple of instance fields (radius and
unitOfMeasure). Naturally, I created a constructor, a couple of
properties and methods. After I got the Circle class working, I used
Program.cs as a driver to test it and everything worked as expected.
After that, I closed my solution and created a new WINDOWS project. I
also called this one "CircleApplication", so it would be in the same
namespace as the Circle class, but named the solution "CircleGUI". I
added a reference to the Circle class, and used the form to create a
simple GUI where I could enter in the radius and unit of measure, and
output the Circumference and Area. Fired it up, and everything worked
like a charm.
When I added the reference to the Circle class, I expected to see one
folder called CircleApplication representing the namespace, with two
project folders inside it. Instead, I had TWO new folders in my
Projects folder ("CircleDriver" and "CircleGUI"), and EACH had a
folder inside named "CircleApplication". I also noticed that a copy
of Circle.cs had been placed in the folder containing my GUI.
As I see things, if I create a project with ten classes (not counting
the GUI), and I want to test each class individually before creating
the main project, like I did the Circle class, I am going to end up
with ten folders, all containing a folder with the same name as the
namespace.
And then when I create the GUI and tie it all together, I'll end up
with an eleventh folder, also containing a subfolder named to match
the namespace, and VS will copy all of the source code files that I
reference over to this folder.
OK, here comes the question.
Is that the way things are done in C#/Visual Studio?
 
T

TomC

Thanks again.

Sorry if I seem dense, but I don't see a folder for the final project
in your hierarchy.

Remember, I am treating the Circle class as if it is something that
needs significant testing BEFORE I'm ready to use it in a "real"
application. That is what the CircleDriver project is - just a way to
test all of the properties and methods.

CircleGUI is supposed to be that "real" application - the final
project. So would there also be a CircleGUI project folder alongside
the CircleDriver folder?

Can the sln file handle two projects in the same solution?

If so, how do I tell it which one to run?

Lastly, when I'm done testing the Circle class in CircleDriver, you
said to manually copy the file to the GUI project. Will I need to
change the namespace identifier?

Apologies for all of the strange questions, but so far, this is really
the only part of C# that I've been having problems with. The rest of
the transition from Java has been fairly smooth, but this VS
environment is completely different than what I am accustomed to. The
IDE's I use with Java are beginners tools, not a professional tool
like VS.

No.

Solution packaging and project packaging are different level of hierarchy
where your projects locates

the uppermost level is the "solution" with is automatically creating for
each new project by default. Solution is just a folder with .sln file where
all other project folders locate

Each project is locates in separate folder, but they should be into the
solution folder

so, u need to have folder hierarchy smth like this
CircleGUI \\ solution folder
+ CircleGUI.sln \\solution file
+ CircleDriver \\ project folder

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog:http://spaces.live.com/laflour

TomC said:
Thanks for the feedback.
Correct me if I am wrong, but it sounds like you are saying that I
should have one project/solution with two namespaces - a "CircleGUI"
namespace, and a "CircleDriver" namespace. And after I use the
CircleDriver to ensure that the Circle class is working properly, I'd
copy and paste that file (Circle.cs) into the CircleGUI namespace and
use it.
If that is correct, will I also have to manually change the identifier
for the namespace in the Circle class from CircleDriver to CircleGUI?
If not, will I run into a problem with the Circle class being
recognized?
Thanks for the info
When your create the CircleGUI and CircleDriver projects two different
solutions were created for you. And this is the reason of problem, I suppose.
Generaly there is only one solution for all projects.
I suppose your need to go other way - create the project with the solution
CircleGUI firstly.
And after that create the CircleDriver project *but* use *the same*
CircleGUI solution for your app
It this case you will have the single solution with different projects inside.
Now you may manually move your CircleDriver project to the CircleGUI solution
--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog:http://spaces.live.com/laflour
:
I know this is long, but please bear with me.
I'm coming from a Java background and trying to get familiar with C#
and Visual Studio for my own benefit. To accomplish that, I have been
doing some experimenting, writing trivial apps to test my
understanding of things.
My latest experiment worked, but NOT in the way that I had
anticipated. I suspect that my question may be as much about VS as it
is about C#. I'll get to the question shortly, but first let me
describe what I have done.
More or less as an intellectual exercise I have created a couple of
trivial applications and gave them the same project name, but
different solution names. The first application was a CONSOLE
application which I gave the highly inventive name
"CircleApplication". I called the solution "CircleDriver".
In this project, I added another class that I called the Circle
class. As the name implies, it merely represents a Circle (I said the
app was trivial) with a couple of instance fields (radius and
unitOfMeasure). Naturally, I created a constructor, a couple of
properties and methods. After I got the Circle class working, I used
Program.cs as a driver to test it and everything worked as expected.
After that, I closed my solution and created a new WINDOWS project. I
also called this one "CircleApplication", so it would be in the same
namespace as the Circle class, but named the solution "CircleGUI". I
added a reference to the Circle class, and used the form to create a
simple GUI where I could enter in the radius and unit of measure, and
output the Circumference and Area. Fired it up, and everything worked
like a charm.
When I added the reference to the Circle class, I expected to see one
folder called CircleApplication representing the namespace, with two
project folders inside it. Instead, I had TWO new folders in my
Projects folder ("CircleDriver" and "CircleGUI"), and EACH had a
folder inside named "CircleApplication". I also noticed that a copy
of Circle.cs had been placed in the folder containing my GUI.
As I see things, if I create a project with ten classes (not counting
the GUI), and I want to test each class individually before creating
the main project, like I did the Circle class, I am going to end up
with ten folders, all containing a folder with the same name as the
namespace.
And then when I create the GUI and tie it all together, I'll end up
with an eleventh folder, also containing a subfolder named to match
the namespace, and VS will copy all of the source code files that I
reference over to this folder.
OK, here comes the question.
Is that the way things are done in C#/Visual Studio?
 
J

Jon Skeet [C# MVP]

Is that the way things are done in C#/Visual Studio?

The problem is adding a reference to a single file - that is *not* how
it's done. Instead, you should have the following (probably all in the
same solution, for ease of development):

1) A class library project containing Circle
2) A test application (or preferably a set of unit tests) which
references the class library *project* (not the individual file)
3) Your GUI application also referencing the class library project

Jon
 
T

TomC

Hi again Jon!

OK, this sounds a little more logical.

So that brings up a follow-up question. VS does so much behind the
scenes for you, that I'm not sure how do do some basic things for
myself - which makes me feel very uncomfortable.

For example, let's say that I create the CircleGUI as my main
application, the Circle class, and a console test application to test
Circle. Pressing F5 in VS will run the main application, but how do I
run the test application without running the main one? I'm sure that
is a trivial matter, but I don't see an easy way to do it in the
menus.
 
J

Jon Skeet [C# MVP]

TomC said:
OK, this sounds a little more logical.

So that brings up a follow-up question. VS does so much behind the
scenes for you, that I'm not sure how do do some basic things for
myself - which makes me feel very uncomfortable.

For example, let's say that I create the CircleGUI as my main
application, the Circle class, and a console test application to test
Circle. Pressing F5 in VS will run the main application, but how do I
run the test application without running the main one? I'm sure that
is a trivial matter, but I don't see an easy way to do it in the
menus.

Right-click on the relevant project and select "Set as start-up
project" (or something similar).

One of the nice things about having unit tests instead is that running
them tends to be a bit easier than keeping changing the startup project
:)
 
T

TomC

Thanks for the info!

I saw that and figured that would be a possibility. I guess I was
hoping for something a little more straightforward. In some of the
Java editors that I have used, each file is in a separate tab, and the
active tab gets run (assuming that it has a main method). But those
are written with beginners in mind, whereas VS is really meant for
pro's.

I haven't tackled learning unit tests yet, but from what I have been
told, they are going to be overkill for what I am doing.

Thanks all!
 

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