如何在 Visual Studio C# 2010 Express 版中创建 DLL 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9308378/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:49:37  来源:igfitidea点击:

How to Create a DLL file in Visual Studio C# 2010 Express edition?

c#visual-studio-2010dll

提问by Rabimba Karanjai

I have already come across the Stack Overflow question "Is there a way to generate a DLL file from Visual Studio Express without explicitly creating a DLL project?", but it does not directly answer my query, so I'm raising it here.

我已经遇到过 Stack Overflow 问题“有没有办法在不显式创建 DLL 项目的情况下从 Visual Studio Express 生成 DLL 文件?”,但它没有直接回答我的查询,所以我在这里提出它。

The problem I am facing while trying to make the DLL is that I can't find any option under Build named build class file. I have changed the project property to class file (shown below)

我在尝试制作 DLL 时面临的问题是我在 Build 命名的构建类文件下找不到任何选项。我已将项目属性更改为类文件(如下所示)

This is how it is:

这是它的样子:

And here is how my build option is getting displayed:

这是我的构建选项的显示方式:

Also when I am using the command-line option the dll file is getting generated but it is not getting the properties I'm setting in the application.

此外,当我使用命令行选项时,正在生成 dll 文件,但没有获取我在应用程序中设置的属性。

I am new with Visual Studio so a litte bit confused about this part.

我是 Visual Studio 的新手,所以对这部分有点困惑。

采纳答案by Justin

The "Build Solution" option in your second screenshot is the thing you need to click to produce your dll, alternatively you can right click on your project in the Solution Explorer and click "Build":

第二个屏幕截图中的“构建解决方案”选项是您需要单击以生成 dll 的内容,或者您​​可以在解决方案资源管理器中右键单击您的项目,然后单击“构建”:

Screenshot of the context menu in the Solution Explorer

解决方案资源管理器中上下文菜单的屏幕截图

(If you only have one project in your solution then these two will both do exactly the same thing)

(如果您的解决方案中只有一个项目,那么这两个项目将做完全相同的事情)

The output dll will normally be placed in the bin\Debugor bin\Releasedirectory depending on whether you are in Release or Debug configuration, check the "Build" tab of the project properties for the exact path.

输出 dll 通常会放置在bin\Debugbin\Release目录中,具体取决于您是处于发布还是调试配置,请检查项目属性的“构建”选项卡以获取确切路径。

The reason why you aren't seeing a "Build class file" option is because this is what the "Build project" menu item does - it will produce a class library if the project output type is "Class Library", a windows executable if the project output type is "Windows Application" etc...

您没有看到“构建类文件”选项的原因是因为这是“构建项目”菜单项所做的 - 如果项目输出类型是“类库”,它将生成一个类库,如果是 Windows 可执行文件项目输出类型是“Windows 应用程序”等...

回答by Jon Skeet

You're not trying to build a class file- you're trying to build a class library.

您不是在尝试构建类文件- 您是在尝试构建类库

And you just build the solution - that will build each of the projectsin your solution, including your LicenseCheckLibraryproject is just a class library project.

您只需构建解决方案 - 这将构建解决方案中的每个项目,包括您的LicenseCheckLibrary项目只是一个类库项目。

It looks like you're basically there - look in the bin\Debugor bin\Releasefolders under LicenseCheckLibrary, and you'll find the DLL.

看起来您基本上就在那里 - 查看LicenseCheckLibrary 下的bin\Debugbin\Release文件夹,您将找到 DLL。

回答by Husein Roncevic

Why would you want to avoid building a DLL file in the first place? Are you developing an EXE file in order to test the logic and then conver it to DLL once it is working fine? If yes, why not create two projects: Windows Console and Class Library. Inside Class Library implement the licensing logic and use Windows COnsole to test the logic. When you say you are new with Visual Studio, what exactly do you mean? You never used it before or you are new to .NET Framework programming? .NET Framework has certain classes for developing licenses. Also, there were quetions here on stackoverflow regarding the licensing. Find some of them instead of reinventing the wheel.

为什么首先要避免构建 DLL 文件?您是否正在开发 EXE 文件以测试逻辑,然后在运行正常后将其转换为 DLL?如果是,为什么不创建两个项目:Windows 控制台和类库。内部类库实现许可逻辑并使用 Windows 控制台来测试逻辑。当你说你是 Visual Studio 的新手时,你到底是什么意思?您以前从未使用过它还是刚接触 .NET Framework 编程?.NET Framework 具有用于开发许可证的某些类。此外,这里有关于 stackoverflow 的关于许可的问题。找到其中的一些而不是重新发明轮子。

Have a look at this article http://www.developer.com/net/net/article.php/3074001

看看这篇文章http://www.developer.com/net/net/article.php/3074001

回答by Rahul Murari

enter image description here

在此处输入图片说明

  1. Create a new class library project
  2. Create classes and code
  3. compile Project
  4. Dll Created
  5. Create a new project
  6. Click on Add Reference
  7. Navigate to the class library folder
  8. Go into the debug folder or whatever and include
  1. 创建一个新的类库项目
  2. 创建类和代码
  3. 编译项目
  4. DLL已创建
  5. 创建一个新项目
  6. 点击添加参考
  7. 导航到类库文件夹
  8. 进入调试文件夹或其他任何并包含

Remember you will prob have to include the namespace. in the new project.

请记住,您必须包含命名空间。在新项目中。