How to Link Class files to multiple projects.

  • Thread starter Thread starter Edward Mitchell
  • Start date Start date
E

Edward Mitchell

I am trying to include two class files into a web service project. The
structure I have is a top level solution and project in a folder and below
that, the web service project in it's own folder. In the top level folder I
have two class files, classA.cs and classB.cs.

In the web service project, I use Add>Existing Item... and browse to select
the files in the parent directory. Unfortunately, when I hit the Open
button in the file select dialog, it makes a COPY of the files into the web
service project folder. I only want one version of a class file around.
Otherwise the maintenance issues are horrendous.

I'm looking for the equivalent to #include... that one would use in a C++
project but I can use that in a C# project.

There was a reference to this problem in this newsgroup on Nov 23, 2001 with
a URL
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#1d8c7bcade03cd7a .

One of the messages in the thread gives this advice:

Ian R Nov 23 2001, 4:20 pm show options

Newsgroups: microsoft.public.dotnet.languages.csharp
From: "Ian R" <[email protected]> - Find messages by this author
Date: Fri, 23 Nov 2001 19:20:08 -0500
Local: Fri, Nov 23 2001 4:20 pm
Subject: Re: how to "#include" a file in C#
Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

Add Existing Item. When the select file dialog appears, highlight the
required file then drop the open button down to link file.





When I select the file(s) in the parent directory, the drop arrow on the
"Open" button only gives me a choice of "Open" or "Open with..." The "Open
with..." allows me to choose a program with which to open the file (such as
XML Schema editor, C# Editor, etc.) but there is no mention of a "Link."

Am I missing something or has VS.NET 2003 changed from what was around in
2001?

Is there a way to share files without creating a library?

Ed
 
I think what you want to do is create a separate Assembly, with your base
classes in it. That will compile to a .dll which you will includeas a
Reference in your other Apps. In VS.Net you can add references to not only
Microsoft assemblies, but also your own assemblies. When you choose Add
Reference, you get a panel with three tabs on it, one of the tabs is
Projects which allows to to add a ref to your other project outputs, or you
can browse to the .dll. When you build you Web app only the .dll will be
copied.

JIM
 
Jim,

Thanks for the feedback. I see now from the help that I can't link to a
file if the project is a Web App. I also have a simple Windows App and in
this Solution the drop down "Open" for "Add Existing Item..." shows three
possibilities, the third being "Link File." The Web App loses this third
line!

I'll follow your advice and create the assembly.

Ed
 
Hi Edward,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to add a link to existing
file. If there is any misunderstanding, please feel free to let me know.

As far as I know, the Web application doesn't support add link to a file.
So I agree with Jim's advice to create the assembly.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Kevin,

You are correct that I thought that I wanted to add a link. Coming from
C++, I expected to have one file for a class, many classes many files and
then share the classes by using the #include statement that isn't used in
C#. I searched this group and found a reference that recommended adding a
link to a file in another directory. Then I found that a Web App can't have
links!

In C++ I'd have to add the .obj files when the project is linked so that is
very similar to adding a library reference in C#. It was just that I was
unfamiliar with the oddities of C#.

Ed
 
Hi Edward,

I'm sorry about the inconvenience, but currently, it seems that the only
workaround is to create the assembly.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top