×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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


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

In the program that uses your dll:
    In Solution Explorer
        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)
        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.

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

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.

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

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close