简体   繁体   中英

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

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.

Visual Studio项目属性->应用程序->输出类型:类库

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM