在 C#.Net 中创建一个 .dll 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15567893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a .dll file in C#.Net
提问by Ambarish
I had created a project which is C# console application project for which I need to call this project dll in another windows application project. I had built the project in visual studio 2010 and checked for .dll
file in bin\debug folder, but it is not created.
我创建了一个项目,它是 C# 控制台应用程序项目,我需要在另一个 Windows 应用程序项目中调用这个项目 dll。我已经在 Visual Studio 2010 中构建了该项目并检查了.dll
bin\debug 文件夹中的文件,但它没有被创建。
But a manifest file and .exe
file havebeen created. Please help me out how to create the .dll
in this case.
但是已经.exe
创建了清单文件和文件。请帮助我.dll
在这种情况下如何创建。
回答by Darren
You need to make a class library and not a Console Application. The console application is translated into an .exe
whereas the class library will then be compiled into a dll
which you can reference in your windows project.
您需要创建一个类库而不是控制台应用程序。控制台应用程序被翻译成一个,.exe
而类库将被编译成一个dll
你可以在你的 Windows 项目中引用的。
- Right click on your Console Application -> Properties -> Change the Output type to Class Library
- 右键单击您的控制台应用程序 -> 属性 -> 将输出类型更改为类库
回答by fhnaseer
You need to change project settings. Right click your project, go to properites. In Application tab change output type to class library instead of Windows application.
您需要更改项目设置。右键单击您的项目,转到属性。在应用程序选项卡中,将输出类型更改为类库而不是 Windows 应用程序。
回答by Xaruth
Console Application is an application (.exe), not a Library (.dll). To make a library, create a new project, select "Class Library" in type of project, then copy the logic of your first code into this new project.
控制台应用程序是一个应用程序 (.exe),而不是一个库 (.dll)。要制作库,请创建一个新项目,在项目类型中选择“类库”,然后将您的第一个代码的逻辑复制到这个新项目中。
Or you can edit the Project Properties and select Class Library instead of Console Application in Output type.
或者您可以编辑项目属性并在输出类型中选择类库而不是控制台应用程序。
As some code can be "console" dependant, I think first solution is better if you check your logic when you copy it.
由于某些代码可能依赖于“控制台”,我认为如果在复制时检查逻辑,第一个解决方案会更好。
回答by Rohit Vyas
To create a DLL File, click on New project, then select Class Library.
要创建 DLL 文件,请单击“新建项目”,然后选择“类库”。
Enter your code into the class file that was automatically created for you and then click Build Solution from the Debug menu.
将您的代码输入到自动为您创建的类文件中,然后从“调试”菜单中单击“构建解决方案”。
Now, look in your directory: ../debug/release/YOURDLL.dll
现在,查看您的目录:../debug/release/YOURDLL.dll
There it is! :)
就在那里!:)
P.S. DLL files cannot be run just like normal applciation (exe) files. You'll need to create a separate project (probably a win forms app) and then add your dll file to that project as a "Reference", you can do this by going to the Solution explorer, right clicking your project Name and selecting Add Reference then browsing to whereever you saved your dll file.
PS DLL 文件不能像普通应用程序 (exe) 文件一样运行。您需要创建一个单独的项目(可能是一个 win 表单应用程序),然后将您的 dll 文件作为“参考”添加到该项目中,您可以通过转到解决方案资源管理器,右键单击您的项目名称并选择添加来执行此操作参考然后浏览到您保存 dll 文件的任何位置。
For more detail please click HERE
欲知更多详情,请点击这里
回答by az fav
Open Visual Studio then select
File
->New
->Project
Select
Visual C#
->Class library
Compile Project Or Build the solution, to create Dll File
Go to the class library folder (Debug Folder)
打开 Visual Studio 然后选择
File
->New
->Project
选择
Visual C#
->Class library
编译项目或构建解决方案,以创建 Dll 文件
转到类库文件夹(Debug Folder)