Project management, multiple directories and namespaces

  • Thread starter Thread starter Charlie Calvert
  • Start date Start date
C

Charlie Calvert

I'm new to C# and am used to Java, where there is a correspondence
between package names and directories. I'm having trouble creating the
same functionality in Visual Studio. In particular, I'm having trouble
compiling such projects.

As an example, suppose I have a project called ConsoleApplication1. It
is stored in a directory called c:\src\ConsoleApplication1. I want to
add a file to this project that is called MyFile.cs and is stored in a
directory called c:\src\ConsoleApplication1\Utils. The source in
MyFile.cs has the following namespace: ConsoleApplication1.Utils.

My problem is accessing a public class declared in MyFile.cs from
ConsoleApplication1.cs. If I try to "Add" MyFile.cs to my project,
Visual Studio has a tendency to copy the file into my current directory.
That is not at all what I want. I want to access the file while it is in
a subdirectory of my main project directory. How do I do this?

I've found something called a References Path in the Properties dialog
for my project, but if it is related to this issue, I don't see how to
use it.

If people feel that all the source code for a C# project should be in
one directory, then please say so. If the solution is to build an
assembly (ie DLL) then please say so, though that is again not at all
what I want to do.

Thank you for your help.

- Charlie
 
Charlie,
That is not at all what I want. I want to access the file while it is in
a subdirectory of my main project directory. How do I do this?

In Solution Explorer, click the Show All Files toolbar button to see
files and directories that aren't included in your project (it should
show the Utils subdirectory and the MyFile.cs file in it). Right-click
MyFile.cs and select Include In Project.



Mattias
 
Hello Charlie

All you need to do is to add a folder to your application by the name utils and then add the file MyFile.cs in the utils folder
and then you wil be able to use your public class in a desired manner

Reason
There is a difference between java package and .net namespace , in java, package always maps to directory structure where as a .net namespace may/may not map to a directory structure. If you want your files (cs or any project related files) to be placed in different folders within the appliction folder then just create those folders from within visual studio.net, vs.net will not manage namepaces accordingly but also will make you feel namespaces much like java packages. Important thing is that
creating namespace (like myApplication.Services) will not create directory Services in myApplication, rather it is the other way around

I hope it serves the purpose

best regards
Hammad.Rajjou

----- Charlie Calvert wrote: ----

I'm new to C# and am used to Java, where there is a correspondence
between package names and directories. I'm having trouble creating the
same functionality in Visual Studio. In particular, I'm having trouble
compiling such projects

As an example, suppose I have a project called ConsoleApplication1. It
is stored in a directory called c:\src\ConsoleApplication1. I want to
add a file to this project that is called MyFile.cs and is stored in a
directory called c:\src\ConsoleApplication1\Utils. The source in
MyFile.cs has the following namespace: ConsoleApplication1.Utils

My problem is accessing a public class declared in MyFile.cs from
ConsoleApplication1.cs. If I try to "Add" MyFile.cs to my project,
Visual Studio has a tendency to copy the file into my current directory.
That is not at all what I want. I want to access the file while it is in
a subdirectory of my main project directory. How do I do this

I've found something called a References Path in the Properties dialog
for my project, but if it is related to this issue, I don't see how to
use it

If people feel that all the source code for a C# project should be in
one directory, then please say so. If the solution is to build an
assembly (ie DLL) then please say so, though that is again not at all
what I want to do

Thank you for your help

- Charli
 
Hammad and Mattias,

Thank you both. You solved my problems. My project had just gotten big
enough so that I had to start organizing it, and you've made it possible
for me to do that.

- Charlie
 

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

Back
Top