Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make a class from one project a dll, then add to another project

Status
Not open for further replies.

Rousseau10

Programmer
Feb 22, 2005
242
US
Hi all,

I am using vs2013 update 4.

I'm having some difficulties and thinking my approach is wrong from the get go.
I have made a "business logic" class in C# console app thinking ahead that I could compile this class to a dll an then
in an MVC project (or any other .Net project for that matter), just add a reference to that dll and a using statement and
the class and it's members would be exposed for me to use.

What I tried:
Created a class library project > added the class I made and tweaked in the console app > compiled it to a dll.
I then Added reference to it in an existing MVC project, added a using statement same name as the class which is also the same name as the dll. Rebalance.dll.
I had no luck. I got the msg (are you missing a directive or assembly reference).

I googled and tried every approach I could find on the web, from using an Imports statement to Unsafe code, using an [attribute] line of code to tell VS I want to use this dll. I tried Unmanaged , interop, and unsafe unmanaged code examples to no avail. Then it hit me that maybe my overall approach was wrong from the beginning. I tried all kinds of approaches. even ILMerge to merge the dll with an exe in a console app just to test that(which defeats the purpose anyway of using an independent dll.) It was just a stab at it.

I know this cannot be that hard.
So please correct me in my initial thinking.
I thought I would just write and test the class in a console app. compile it to a dll. Then add a reference to it in another project with a using statement.
And voowallaa. I could go:


using...;
using NewBalance;

namespace FOOBAR
{
class Test
{

Rebalance nb = new ReBalance();
int RemainingDays = nb.GetRemainingDays(ReceivedDate,ReplenishDate);

};
};


But all I got was the msg (are you missing a directive or assembly reference).

How do I need to do this?

Thanks in advance!
Adam


 
In the program that uses your dll:
[tab]In Solution Explorer
[tab][tab]Right Click on References, select Add Reference, locate and select your dll using the Browse dialog box and click OK (or whatever to accept (I can't remember exactly what the button is called - it might be Save)
[tab][tab]Once your dll has been added, locate the entry in References in Solution Explorer and in the Properties Window make sure that CopyLocal is set to True.

You can now reference the dll in your code in the normal way (eg by using the using statement)

I don't have VS currently running, but I am 99.99% certain that I have covered all the necessary steps. If I have missed something, you should be able to see what is needed in the dialog box.
 
Instead of browsing for your DLL you can filter what assemblies you want to reference on the left side. Among them you can filter for "Solution" - all assemblies generated within the same solution. There you find all projects, even before building them.

Bye, Olaf.
 
Thanks so much guys.

After looking closely at your code, I realized I forgot to put the access specifier of "public" before my class so it defaulted to "private" and therefore inaccessible to the other project.

I had

class NewBalance{

instead of

public class NewBalance {


devils in the details !

Thanks so much! .

Adam


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top