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
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 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
Bye, Olaf.
RE: how to make a class from one project a dll, then add to another project
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