Sergey
Sergey

Reputation: 11928

Pack C# project to dll or another library

I have a C# project with many classes. Is it possible to pack this project(Console application) into library(maybe dll or anything else) and invoke all functions of a definite class from other programming languages?

EDIT: Here is the code:

using System;
using System.Text;

namespace Test { class Program { public int aplusb(int a, int b) { return a + b; }

    public void hello()
    {
        Console.WriteLine("Helo world");
    }
}

} And the hierarchy in project folder: - Properties - References - bin -- Debug --- Test.dll --- Test.exe --- Test.pdb --- Test.vshost.exe --- Test.vshost.exe.manifest - obj -- x86 ---Debug ----TempPE ----- DesignTimeResolveAssemblyReferencesInput.cache ----- Test.csproj.FileListAbsolute.txt ----- Test.dll ----- Test.pdb ----- ResolveAssemblyReference.cache - Program.cs

I checked both Test.dll from bin and obj. They are empty

Upvotes: 1

Views: 3243

Answers (4)

ErikHeemskerk
ErikHeemskerk

Reputation: 1701

Class libraries you create with .NET (which end up being DLLs) are only usable from within other .NET applications or libraries, or - if you choose to enable it - from COM.

As far as I know, it's not possible to create a DLL with C# whose methods you can then call from an unmanaged application (C, C++, etc.). There are no so called 'exported methods', which is why DLL viewer shows it to be empty. Check again using .NET Reflector or a similar decompiler, and you'll see the methods show up.

Upvotes: 0

hcb
hcb

Reputation: 8357

Yes, you can create a class library project. Just keep in mind you are creating a dll with managed code, if you want to use it in for example c++ you have to do some extra stuff.

Upvotes: 0

Mahesh KP
Mahesh KP

Reputation: 6446

when you build the project you get the dll in the corresponding bin folder.

You can use this dll in other project by adding reference to this dll. After that you can use its methods.

Upvotes: 2

Dummy01
Dummy01

Reputation: 1995

Visual Studio Project Properties -> Application -> Output Type: Class Library

Upvotes: 0

Related Questions