如何在visual studio 2012中从我的解决方案或项目创建DLL?

人气:416 发布:2022-09-22 标签: visual-studio dll vs2012

问题描述

好的,所以几年前我曾经编程过。我记得,有一次,我从我的解决方案/项目中创建了一个可执行文件或程序集或DLL或者它所调用的任何东西。这是次要而不复杂的事情。无论如何,我只是抓住那个DLL文件或其他任何东西并将其移动到我的主机上,当我转到该文件的文件夹时,可执行文件已执行,所有内容都按预期在Web上运行。 大约4年后,我已经很久没有使用VS了,更不用说我现在使用的VS2012。那么,我该如何创建这个DLL或程序集或者我4年前创建的任何东西(我几乎可以肯定它是一个dll程序集)?如果有人能指出我正确的方向,我会很感激。 谢谢

Ok, so I used to program years ago. I remember that, at one point, I created an executable or an assembly or a DLL or whatever it was called, out of my solution/project. It was something minor and not complicated. Anyway, I simply grabbed that DLL file or whatever it was and moved it to my hosting and when I went to the folder of that file, the executable executed and everything worked on the web as expected. It's been about 4 years later and I have not used VS in a long time, much less VS2012, which I'm using now. So, how do I go about creating this DLL or assembly or whatever it was I created 4 years ago (I'm almost sure it was a dll assembly)? If anyone could point me in the right direction, I'll appreciate it. Thanks

推荐答案

您不是从解决方案(甚至是EXE文件)创建DLL ) - 你从解决方案中的项目创建这些。 所以一个解决方案可能包含三个项目,它们生成一个EXE和两个DLL文件。 从项目创建DLL很简单:通过右键单击解决方案资源管理器窗格中的解决方案名称并选择添加...新建项目...,将项目添加到解决方案中。在结果对话框中,从中间面板中选择类库并为其指定适当的名称。按OK。 构建项目(或解决方案)时,将自动创建DLL文件。 (您可能希望在任何EXE项目中添加对DLL项目的引用,以便使用您创建的类和方法) OriginalGriff,但这些DLL文件在哪里?正如我所提到的,我只想将我需要的任何DLL或可执行文件移动到托管站点,用户只需转到特定的URL并执行该文件即可并且它将被运行。 谢谢 如果你真的在谈论URL(因此也就是互联网上的位置),那就相当复杂了 - 用户无法像在他自己的网站上那样轻松地运行远程计算机上的文件(如果没有别的话可以阻止恶意运行您不希望由不想运行它们的人运行的程序!)。相反,程序通过网站在URL上运行 - 这不难安排,但需要不同的思维方式。 如果您只是使用 URL错误,用户可以导航到包含文件的文件夹,然后将在目录结构下的Solution文件夹中创建普通exe文件。因此,如果您的解决方案被称为MyWallet并且它是在D:\ MyProjects中创建的,则使用EXE项目MyExe和DLL项目MyDLL,然后: You don't create a DLL from a solution (or even an EXE file) - you create these from a Project within a solution. So a Solution may contain three Projects, which generate an EXE and two DLL files. To create a DLL from a project is easy: Add the Project to your Solution by right clicking the solution name in the Solution Explorer pane and selecting "Add...New Project...". In the resulting dialog, select "Class Library" from the middle panel and give it an appropriate name. Press OK. When you build the project (or solution) the DLL file will be created automatically. (You may want to add a reference to the DLL project in any EXE project in order to use the classes and methods you create) "OriginalGriff, but where are these DLL files? As I mentioned, I just want to move whichever DLL or executable file I need to a hosting site where the user can simply go to a particular URL and the file will be executed and it'll be run. Thanks" If you are genuinely talking about URLs (and hence a location on the internet) then that's rather more complex - the user can't run a file on a remote computer as easily as on his own (if nothing else to stop malicious running of programs you don't want run by people you don't want to run them!). Instead, programs are run on URLs via websites - which isn't difficult to arrange, but needs a different way of thinking. If you are just using the term "URL" wrong, and the user can navigate to the folder in which the file will be contained, then a "normal" exe file will be created in your Solution folder under a directory structure. So, if your Solution is called "MyWallet" and it is created in "D:\MyProjects", with an EXE Project "MyExe" and a DLL project "MyDLL" then:
D:\My Projects\MyWallet\MyExe\bin\Debug

将保存调试EXE文件

Will hold the debug EXE file

D:\My Projects\MyWallet\MyExe\bin\Release

将提供发布版本。 和

Will hoild the release version. And

D:\My Projects\MyWallet\MyDLL\bin\Debug
D:\My Projects\MyWallet\MyDLL\bin\Release

对于DLL文件将保持相同。 如果您不确定系统中这些路径的位置,那么: 1)右键单击您在VS中的项目名称并选择属性。 2)查看构建选项卡,底部附近是输出路径。 3)按浏览按钮,将打开Windows浏览窗口,让您看到路径。

Will hold the same for the DLL files. If you aren't sure where these paths are in your system, then: 1) Right click your project name in VS and select "Properties". 2) Look at the "Build" tab, and near the bottom is the "Output Path". 3) Press the "Browse" button and a Windows Explore window will open letting you see the path.

595