简体   繁体   English

C# 如何将 DLL 中的引用与 DLL 一起加载?

[英]C# How do I load the references in the DLL together with the DLL?

I'm adding another project as a DLL reference to my Console Application project that I created with C# .NET 6.0.我正在添加另一个项目作为对我使用 C# .NET 6.0 创建的控制台应用程序项目的 DLL 引用。

In this DLL project, the reference Microsoft.Data.SqlClient is used, but this reference does not come with the added DLL.在此 DLL 项目中,使用了引用 Microsoft.Data.SqlClient,但添加的 DLL 不附带此引用。

I need to add the Microsoft.Data.SqlClient reference separately to my Console Application project.我需要将 Microsoft.Data.SqlClient 引用单独添加到我的控制台应用程序项目中。 I have many references like this.我有很多这样的参考资料。

How can I ensure that the references used in the DLL are loaded together with the DLL?如何确保 DLL 中使用的引用与 DLL 一起加载?

One way to do it, is to create a nuget package out of it, in which you include the dependencies, more on this here (nuget) and here: creating-a-package or like this .一种方法是从中创建一个nuget package ,其中包含依赖项,更多关于 这里 (nuget)和这里:create -a-package或 like this If you then install the package into your new project, it will include the dependencies as well.如果您随后将包安装到您的新项目中,它也将包含依赖项。

Alternatively you can just add the Microsoft.Data.SqlClient reference to your project.或者,您可以将Microsoft.Data.SqlClient引用添加到您的项目中。

There are all sorts of hacks to include the DLL as resource in yours, but I would stay away from that.有各种各样的技巧可以将 DLL 作为资源包含在您的资源中,但我会远离它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM