473,748 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a single CLASS file that will be available to ANY PROJECT I want to link it to???

Again, I'm new to VB.net and there is something I need help with:

Like (I assume) many of us, over time I want to be able to create some
VB.net classes that I might want to use in more than one Project. So
let's say I've created a Folder called "MyVBNet Classes" to hold these
general-use VB.Net class files that I will eventually associate with
various Projects I create. Now let's imagine I've created a class
called "MyClass.vb " that I've placed into the "MyVBNetClasses " folder.
Let's also assume that, over time, I will be adding code to
"MyClass.vb ", but the new code will never be written in a
Project-specific manner. In other words, I will only add code to
"MyClass.vb " that will keep it capable of providing general-use to any
Project that may need it.

My assumption has been that if I create a new project and want to
utilize my general-use "MyClass.vb " class in the project that I just
Right-Click the Solution in my new project's Solution Explorer, click
Add, click Existing Item, and then go to the "MyVBNet Classes" folder
and select "MyClass.vb " from it. So far so good...

....except that what this seems to result in is a copy of "MyClass.vb "
is created in my current Project's folder.

This (I think) is a problem. As I've said, I'm very careful to alter
this type of general-use class file in such a way that it won't become
project-specific; because I want to be able to drop this class where
needed into any project.

But, as I say, the process I've described above seems to create a new
separate and distinct "MyClass.vb " file. Presumably, if I make any
changes to that class while I'm working in a Project, I will ONLY BE
ALTERING THE VERSION of "MyClass.vb " that is in *that particular
Project's folder system*.

I hope somebody will tell me I'm doing this wrong because, given what
I've stated above, this defeats the whole purpose of being able to
create single general-use Classes that will get improved over time but
will be commonly available to any Project I begin to create.

That said, what am I doing wrong here?

Thanks in advance for any help.
Nov 5 '07 #1
4 4470
You are correct that a copy of the .vb file is being made. This is because
VB .NET projects have to have a master project folder that all project items
will be inside of (including sub-folders you may wish to make inside of the
project folder). You can't just have random files that are outside of the
project directory structure be part of your project.

Having said this, IMHO, you are going about this all wrong.

Rather than keeping a source code file hanging around (and getting copies
created each time you want to use it), why not just compile your general
purpose code into a .dll, install that assembly into the GAC and then you
can reference that library from any other project you wish to (without
having to make copies of the .dll). If you wanted to extend the code, you
can simply use inheritance to do that.

-Scott

"Alan Mailer" <cl**********@e arthlink.netwro te in message
news:f5******** *************** *********@4ax.c om...
Again, I'm new to VB.net and there is something I need help with:

Like (I assume) many of us, over time I want to be able to create some
VB.net classes that I might want to use in more than one Project. So
let's say I've created a Folder called "MyVBNet Classes" to hold these
general-use VB.Net class files that I will eventually associate with
various Projects I create. Now let's imagine I've created a class
called "MyClass.vb " that I've placed into the "MyVBNetClasses " folder.
Let's also assume that, over time, I will be adding code to
"MyClass.vb ", but the new code will never be written in a
Project-specific manner. In other words, I will only add code to
"MyClass.vb " that will keep it capable of providing general-use to any
Project that may need it.

My assumption has been that if I create a new project and want to
utilize my general-use "MyClass.vb " class in the project that I just
Right-Click the Solution in my new project's Solution Explorer, click
Add, click Existing Item, and then go to the "MyVBNet Classes" folder
and select "MyClass.vb " from it. So far so good...

...except that what this seems to result in is a copy of "MyClass.vb "
is created in my current Project's folder.

This (I think) is a problem. As I've said, I'm very careful to alter
this type of general-use class file in such a way that it won't become
project-specific; because I want to be able to drop this class where
needed into any project.

But, as I say, the process I've described above seems to create a new
separate and distinct "MyClass.vb " file. Presumably, if I make any
changes to that class while I'm working in a Project, I will ONLY BE
ALTERING THE VERSION of "MyClass.vb " that is in *that particular
Project's folder system*.

I hope somebody will tell me I'm doing this wrong because, given what
I've stated above, this defeats the whole purpose of being able to
create single general-use Classes that will get improved over time but
will be commonly available to any Project I begin to create.

That said, what am I doing wrong here?

Thanks in advance for any help.

Nov 5 '07 #2
Scott, thanks for the advice. Could you either talk me through a
step-by-step way of going about your suggestion... or perhaps
recommend a book or website that might provide this?

Again, I'm new to VB.net and (for well or ill) did not handle things
the way you suggest in my VB6 days.

Thanks again for any feedback.

On Mon, 5 Nov 2007 17:04:00 -0500, "Scott M." <s-***@nospam.nosp am>
wrote:
>You are correct that a copy of the .vb file is being made. This is because
VB .NET projects have to have a master project folder that all project items
will be inside of (including sub-folders you may wish to make inside of the
project folder). You can't just have random files that are outside of the
project directory structure be part of your project.

Having said this, IMHO, you are going about this all wrong.

Rather than keeping a source code file hanging around (and getting copies
created each time you want to use it), why not just compile your general
purpose code into a .dll, install that assembly into the GAC and then you
can reference that library from any other project you wish to (without
having to make copies of the .dll). If you wanted to extend the code, you
can simply use inheritance to do that.

-Scott

"Alan Mailer" <cl**********@e arthlink.netwro te in message
news:f5******* *************** **********@4ax. com...
>Again, I'm new to VB.net and there is something I need help with:

Like (I assume) many of us, over time I want to be able to create some
VB.net classes that I might want to use in more than one Project. So
let's say I've created a Folder called "MyVBNet Classes" to hold these
general-use VB.Net class files that I will eventually associate with
various Projects I create. Now let's imagine I've created a class
called "MyClass.vb " that I've placed into the "MyVBNetClasses " folder.
Let's also assume that, over time, I will be adding code to
"MyClass.vb" , but the new code will never be written in a
Project-specific manner. In other words, I will only add code to
"MyClass.vb " that will keep it capable of providing general-use to any
Project that may need it.

My assumption has been that if I create a new project and want to
utilize my general-use "MyClass.vb " class in the project that I just
Right-Click the Solution in my new project's Solution Explorer, click
Add, click Existing Item, and then go to the "MyVBNet Classes" folder
and select "MyClass.vb " from it. So far so good...

...except that what this seems to result in is a copy of "MyClass.vb "
is created in my current Project's folder.

This (I think) is a problem. As I've said, I'm very careful to alter
this type of general-use class file in such a way that it won't become
project-specific; because I want to be able to drop this class where
needed into any project.

But, as I say, the process I've described above seems to create a new
separate and distinct "MyClass.vb " file. Presumably, if I make any
changes to that class while I'm working in a Project, I will ONLY BE
ALTERING THE VERSION of "MyClass.vb " that is in *that particular
Project's folder system*.

I hope somebody will tell me I'm doing this wrong because, given what
I've stated above, this defeats the whole purpose of being able to
create single general-use Classes that will get improved over time but
will be commonly available to any Project I begin to create.

That said, what am I doing wrong here?

Thanks in advance for any help.
Nov 5 '07 #3
When you create a new Project just select Visual Basic->Windows->Class
Library

This will automatically create a dll. You can then reference this Dll
(using Add References) from any other project. Your new project can
reference anything that was made public from that DLL. This will end up
making a copy of your dll for each project, however, if you only want one
copy you need to use the GAC.

To use the GAC you need to create a strongly typed assembly. You can google
GAC & Strongly typed assembly and you'll get plenty of examples.

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"Alan Mailer" <cl**********@e arthlink.netwro te in message
news:bi******** *************** *********@4ax.c om...
Scott, thanks for the advice. Could you either talk me through a
step-by-step way of going about your suggestion... or perhaps
recommend a book or website that might provide this?

Again, I'm new to VB.net and (for well or ill) did not handle things
the way you suggest in my VB6 days.

Thanks again for any feedback.

On Mon, 5 Nov 2007 17:04:00 -0500, "Scott M." <s-***@nospam.nosp am>
wrote:
>>You are correct that a copy of the .vb file is being made. This is
because
VB .NET projects have to have a master project folder that all project
items
will be inside of (including sub-folders you may wish to make inside of
the
project folder). You can't just have random files that are outside of
the
project directory structure be part of your project.

Having said this, IMHO, you are going about this all wrong.

Rather than keeping a source code file hanging around (and getting copies
created each time you want to use it), why not just compile your general
purpose code into a .dll, install that assembly into the GAC and then you
can reference that library from any other project you wish to (without
having to make copies of the .dll). If you wanted to extend the code,
you
can simply use inheritance to do that.

-Scott

"Alan Mailer" <cl**********@e arthlink.netwro te in message
news:f5****** *************** ***********@4ax .com...
>>Again, I'm new to VB.net and there is something I need help with:

Like (I assume) many of us, over time I want to be able to create some
VB.net classes that I might want to use in more than one Project. So
let's say I've created a Folder called "MyVBNet Classes" to hold these
general-use VB.Net class files that I will eventually associate with
various Projects I create. Now let's imagine I've created a class
called "MyClass.vb " that I've placed into the "MyVBNetClasses " folder.
Let's also assume that, over time, I will be adding code to
"MyClass.vb ", but the new code will never be written in a
Project-specific manner. In other words, I will only add code to
"MyClass.vb " that will keep it capable of providing general-use to any
Project that may need it.

My assumption has been that if I create a new project and want to
utilize my general-use "MyClass.vb " class in the project that I just
Right-Click the Solution in my new project's Solution Explorer, click
Add, click Existing Item, and then go to the "MyVBNet Classes" folder
and select "MyClass.vb " from it. So far so good...

...except that what this seems to result in is a copy of "MyClass.vb "
is created in my current Project's folder.

This (I think) is a problem. As I've said, I'm very careful to alter
this type of general-use class file in such a way that it won't become
project-specific; because I want to be able to drop this class where
needed into any project.

But, as I say, the process I've described above seems to create a new
separate and distinct "MyClass.vb " file. Presumably, if I make any
changes to that class while I'm working in a Project, I will ONLY BE
ALTERING THE VERSION of "MyClass.vb " that is in *that particular
Project's folder system*.

I hope somebody will tell me I'm doing this wrong because, given what
I've stated above, this defeats the whole purpose of being able to
create single general-use Classes that will get improved over time but
will be commonly available to any Project I begin to create.

That said, what am I doing wrong here?

Thanks in advance for any help.
Nov 6 '07 #4
Create a new "Class Library" project and in it create one or more classes
with public methods that do your general purpose tasks. Build this project
and then you will have a single .dll that contains this/these classes and
their coresponding methods.

When you want to use these classes from another project. Just make a
reference to the .dll file you made earlier and you'll be able to use the
public methods within it. Now, if you just do this, you'd be fine, but you
did say that you don't want to have multiple copies of the same file kicking
around (although, I think you should re-think that as having multiple .dll's
contained in the various projects that will use them isn't a bad idea).

If you wanted to go a step further, you could strong name your .dll and
install it into the Global Assembly Cache (GAC) so that just one copy of it
could be used for as many projects as you'd like. The strong naming/GAC
installation process is not hard or lengthy, but too much to type here, so
here is a link on the process:

http://aspalliance.com/394_Installin...bly_in_GAC.all


"Alan Mailer" <cl**********@e arthlink.netwro te in message
news:bi******** *************** *********@4ax.c om...
Scott, thanks for the advice. Could you either talk me through a
step-by-step way of going about your suggestion... or perhaps
recommend a book or website that might provide this?

Again, I'm new to VB.net and (for well or ill) did not handle things
the way you suggest in my VB6 days.

Thanks again for any feedback.

On Mon, 5 Nov 2007 17:04:00 -0500, "Scott M." <s-***@nospam.nosp am>
wrote:
>>You are correct that a copy of the .vb file is being made. This is
because
VB .NET projects have to have a master project folder that all project
items
will be inside of (including sub-folders you may wish to make inside of
the
project folder). You can't just have random files that are outside of the
project directory structure be part of your project.

Having said this, IMHO, you are going about this all wrong.

Rather than keeping a source code file hanging around (and getting copies
created each time you want to use it), why not just compile your general
purpose code into a .dll, install that assembly into the GAC and then you
can reference that library from any other project you wish to (without
having to make copies of the .dll). If you wanted to extend the code, you
can simply use inheritance to do that.

-Scott

"Alan Mailer" <cl**********@e arthlink.netwro te in message
news:f5****** *************** ***********@4ax .com...
>>Again, I'm new to VB.net and there is something I need help with:

Like (I assume) many of us, over time I want to be able to create some
VB.net classes that I might want to use in more than one Project. So
let's say I've created a Folder called "MyVBNet Classes" to hold these
general-use VB.Net class files that I will eventually associate with
various Projects I create. Now let's imagine I've created a class
called "MyClass.vb " that I've placed into the "MyVBNetClasses " folder.
Let's also assume that, over time, I will be adding code to
"MyClass.vb ", but the new code will never be written in a
Project-specific manner. In other words, I will only add code to
"MyClass.vb " that will keep it capable of providing general-use to any
Project that may need it.

My assumption has been that if I create a new project and want to
utilize my general-use "MyClass.vb " class in the project that I just
Right-Click the Solution in my new project's Solution Explorer, click
Add, click Existing Item, and then go to the "MyVBNet Classes" folder
and select "MyClass.vb " from it. So far so good...

...except that what this seems to result in is a copy of "MyClass.vb "
is created in my current Project's folder.

This (I think) is a problem. As I've said, I'm very careful to alter
this type of general-use class file in such a way that it won't become
project-specific; because I want to be able to drop this class where
needed into any project.

But, as I say, the process I've described above seems to create a new
separate and distinct "MyClass.vb " file. Presumably, if I make any
changes to that class while I'm working in a Project, I will ONLY BE
ALTERING THE VERSION of "MyClass.vb " that is in *that particular
Project's folder system*.

I hope somebody will tell me I'm doing this wrong because, given what
I've stated above, this defeats the whole purpose of being able to
create single general-use Classes that will get improved over time but
will be commonly available to any Project I begin to create.

That said, what am I doing wrong here?

Thanks in advance for any help.

Nov 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2946
by: LP | last post by:
Hi, I have a site which runs on .Net technology. The site is already deployed and running. I need to change 1 file for some small enhancement. Please tell me, how can I compile that 1 file and merge it to the original DLL (the one deployed on the live server) so as to upgrade it. I dont want to recompile the whole project for the 1 file Regards,. LP
2
13410
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class template and by setting output to a type library (DLL). All the object does is return a string value. At this point I have not checked the option to register for COM interop in Visual Studio So I go into Excel (where I want to use the object). Go to VB...
7
8866
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
8
4525
by: Ted Miller | last post by:
Hi folks, I'm looking at moving a large base of C++ code to .Net under tight time constraints. The code runs in mission-critical environments, and I am extremely concerned about the loader lock problem and the potential for deadlocks. After pouring over the available information, and trying a few experiments, I am still left with a few questions and issues I hope someone out there can shed some light on.
10
2314
by: Tim Mulholland | last post by:
My company is about to begin working on an ASP.NET application. There are going to be two primary developers working on this project. It will be a fairly deep project (lots of lines of code) but not a very wide project (pretty much limited to a few purposes, not many ways to split it up). I've done alot of ASP.NET development before by myself so writing the application shouldn't be an issue, but my question is this: How do multiple...
15
26513
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
3
14944
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim swLog As StreamWriter = File.CreateText("C:\myLog.txt") swLog.WriteLine("My Windows Service has just started.") swLog.Close() : swLog.Flush() End Sub
11
8319
by: Amadrias | last post by:
Hi, In one of my current projects, I am willing to create a secure zone such as Acronis does in its application to store some confidential information only accessible to the current machine user. I know that .Net doesn't provide such functionalities therefore I went on MSDN Library and also on Google to look for any solution with no result... I first guessed that using WMI it could be doable (System.Management
5
6776
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9359
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9236
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8235
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.