visual-studio 如何将程序集添加到 Visual Studio 项目并引用它?

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

How do I add an assembly to a Visual Studio project and reference it?

.netvisual-studiodllassembliesreference

提问by Ben McCormack

I've compiled an assembly for MySql.Data.dlland would like to add it to a new Visual Studio Project. I'm lost on the correct terminology and how best to go about this, but the end goal is to distribute this dll so that it's included with the application when the application runs. This is to avoid having to GAC the dll on the end user's machine.

我已经编译了一个程序集,MySql.Data.dll并希望将其添加到新的 Visual Studio 项目中。我迷失了正确的术语以及如何最好地解决这个问题,但最终目标是分发此 dll,以便在应用程序运行时将其包含在应用程序中。这是为了避免在最终用户的机器上对 dll 进行 GAC。

I've tried simply copying the assembly into the project folder:

我试过简单地将程序集复制到项目文件夹中:

However, I can't figure out how to add a reference to that dll in the current project. Nor have I figured out how to ensure that this dll will "stay with" the application once it is compiled. How might this be accomplished and what other things might I consider?

但是,我不知道如何在当前项目中添加对该 dll 的引用。我也没有想出如何确保这个 dll 在编译后“留在”应用程序中。这将如何实现?我还可以考虑哪些其他事项?

回答by JaredPar

Try the following

尝试以下

  • Right cilck on the References Node
  • Choose "Add Reference"
  • Click on the Browse tab
  • Navigate to the dll MySql.Data.dll on disk and hit OK
  • 右键单击引用节点
  • 选择“添加参考”
  • 单击“浏览”选项卡
  • 导航到磁盘上的 dll MySql.Data.dll 并点击 OK

Once it's added, click on the reference under the References folder and hit F4. This will bring up the properties tool window. Make sure it is set to "Copy Local" = True. This will ensure it gets deployed with your application by the standard installers (MSI and ClickOnce)

添加后,单击“引用”文件夹下的引用并按 F4。这将打开属性工具窗口。确保将其设置为“复制本地”= True。这将确保它由标准安装程序(MSI 和 ClickOnce)与您的应用程序一起部署

回答by Keith Adler

Right-click on References and select Add Reference..., navigate to the to DLL and presto ... you're done.

右键单击“引用”并选择“添加引用...”,导航到 DLL 并快速...大功告成。

回答by Brandon

Right Click References -> Add Reference -> Wait forever for the list to load -> Browse -> Select your Dll

右键单击引用 -> 添加引用 -> 永远等待列表加载 -> 浏览 -> 选择您的 Dll

Then when it has been added to the reference list, set it to Copy Local (if it is not already). This will put it in the output folders for you.

然后当它被添加到引用列表时,将它设置为复制本地(如果还没有)。这会将其放入输出文件夹中。

回答by Charlie Brown

Right click on the "References" folder in the list and choose Add reference. On the Browse tab, browse to the directory containing your project, and the subfolder. Select the assembly and add it to the project.

右键单击列表中的“参考”文件夹,然后选择“添加参考”。在“浏览”选项卡上,浏览到包含项目的目录和子文件夹。选择程序集并将其添加到项目中。

回答by Sam Holder

Right click on the project in Solution Explorerand select 'Add Reference...'. Then you can browse to the file.

右键单击解决方案资源管理器中的项目,然后选择“添加引用...”。然后您可以浏览到该文件。