通过引用在C#中的另一个应用程序提供的外部.NET的DLL应用程序、NET、DLL

2023-09-03 17:17:16 作者:俄会哭ξ但绝不会认输

我有一个C#项目,它引用一个DLL(称之为外部DLL),它带有另一个应用程序。当我建立我的项目,由于参考的外部DLL被自动添加到我的项目输出。当我运行我的项目,它加载外部DLL从我的项目文件夹。

I have a C# project which references a DLL (call it external DLL) which comes with another application. When I build my project, due to the reference, the external DLL gets automatically added to my project output. And when I run my project it loads the external DLL from my project folder.

其他的应用程序,它的外部DLL所属的由其他团队开发和DLL定期更新。我不想用我的项目包装自己的DLL。相反,我想有执行的时候,我的项目加载DLL的 - 而不是从我的项目的文件夹,挑DLL副本

The other application, which the external DLL belongs to, is developed by another team and the DLL is regularly updated. I don't want to package their DLL with my project. Instead I would like to have my project load their DLL when executed -- rather than pick the DLL copy from my project's folder.

现在我知道这是可能通过反射。我知道我可以做一个的Assembly.Load,并选择该DLL。但是,因为我用的类型从外部DLL全部通过我的code,我想code是静态类型检查。

Now I know that this is possible through reflection. I know that I can do an "Assembly.Load" and pick the DLL. But because I use the types from the external DLL all through my code, I would like the code to be statically type checked.

下面是我想:

可以通过引用外部DLL编译我的项目,从而获得静态类型检查。 当项目运行时,外部DLL被拾起从其他应用程序的文件夹,这是在我的项目的输出文件夹中的DLL而不是拷贝。

有什么办法来解决这个问题?有没有添加引用和使用反射之间的一些中间立场?

Is there any way to solve this problem? Is there some middle ground between adding a reference and using reflection?

推荐答案

最immediete解决问题的方法是改变引用的属性。有一个名为复制本地设置。设置为false,它就会停止复制该DLL到项目的输出。您可以通过展开引用文件夹在解决方案中,右键单击有问题的参考,然后单击属性打开属性面板访问引用的属性。

The most immediete solution to your problem is to change the properties of the reference. There is a setting called Copy Local. Set that to false and it'll stop copying the DLL to your project's output. You can access the properties of the reference by expanding the references folder in your solution, right-clicking on the reference in question, and clicking properties to open the properties pane.

这是Visual Studio中复制DLL到项目的输出文件夹在制作的时候其实并不重要的.Net框架运行时的事实。所有重要的是可用的框架无论是在其搜索路径或在全局程序集缓存中您引用的程序集。

The fact that Visual Studio copies the DLL to your project's output folder at build time doesn't really matter to the .Net Framework at runtime. All that matters is that the assemblies you reference are available to the framework either in the paths it searches or in the global assembly cache.

 
精彩推荐
图片推荐