By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,947 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,947 IT Pros & Developers. It's quick & easy.

Project management, multiple directories and namespaces

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

P: n/a
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

Nov 16 '05 #3

P: n/a
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
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.