[RESOLVED] [1.0/1.1] Referencing other classes
In VB 6.0 I was able to access a common class module in several of my projects. I never compiled this module as a DLL since I did not want to distribute a DLL along with the program.
I am trying to do the same thing in C#. I have a class module that I would like to add common methods to and then be able to access those methods from various classes. So from the project, I selected Add --> Add an existing item and selected the common class file. The class was added and I continued to work. Want I neglected to notice was that VS 2003, COPIED the class file into my project. This defeated the purpose of me having a common class.
Are you not allowed to reference class files like I did in VB 6.0?
I hope that made sense.
Steve
Re: [1.0/1.1] Referencing other classes
I don't see the problem here.
see, even if you add the class to the project it doesn't mean it'll be accessible from outside the project, (mark it internal instead of public for that).
VS will Not compile a DLL file for the each class you have
Re: [1.0/1.1] Referencing other classes
Also, each file that is created in C# is a class file (I think it's the same in VB.Net, only the extensions are different).
I guess, you want to group the common utility methods into one class file and then make a DLL of that. That you can achieve by having a separate project(DLL) for all such class files and then you can refer to that project and all its methods in your current project(UI). But if you are going to have only 1 class file for such methods then from maintainability point of view ComputerJy's suggestion is a better solution.
Hope I'm making sense.
Re: [1.0/1.1] Referencing other classes
I think I am missing something here. Let me try this another way. Normally what I could do is create a DLL with all of the methods I need and then reference that DLL from within Mainprogone.cs and Mainprogtwo.cs shown in option one.
Option One
Commondll.proj
**String.cs
Projectone.proj
**Mainprogone.cs
Projecttwo.proj
**Mainprogtwo.cs
What I was hoping to do through was avoid creating the DLL and instead add the file String.cs to each of my projects. Whatever change I made to String.cs will take affect in both projects, as shown in option two.
Option Two
Projectone.proj
**Mainprogone.cs
**String.cs
Projecttwo.proj
**Mainprogtwo.cs
**String.cs
Is this possible?
Re: [1.0/1.1] Referencing other classes
you can use "Pre-build event command line" to launch a ".bat" file that copies the file to the other project
Re: [1.0/1.1] Referencing other classes
Thank you for the reply back. OK the short answer is that you can’t easily do this. Do you know a reason why Microsoft elected not to allow referencing of .cs files between projects?
I guess I will build a common DLL now.
Re: [1.0/1.1] Referencing other classes
Because they're sticking to OOPer concepts, and so the assemblies need to be compiled before they can be used. Hence, the requirement that your code be included, rather than 'sit' separately. With .NET, a lot of VB6 concepts go out the 19th floor window.
Re: [1.0/1.1] Referencing other classes
Thanks I can't say I like the idea. I can't see why an assembly can't be compiled using a .cs file from another project. Obviously I don't have a clue.