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 开发者_StackOverflowobj. 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 Project Properties -> Application -> Output Type: Class Library
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.
精彩评论