简体   繁体   English

如何在UWP中使用C#dll

[英]How to use C# dll in UWP

I have a C# dll compiled in .net framework 2.0 and the library is not been updated by the vendor till now. 我在.net framework 2.0中编译了一个C#dll,到目前为止该供应商尚未更新该库。 In one of my desktop application C# i was using that and when i migrated the application to WPF, the same libraries where referred and working fine. 在我的一个桌面应用程序中,C#i正在使用它,当我将应用程序迁移到WPF时,相同的库被引用并且工作正常。 Now, the application required new diversion, as it should be upgraded to UWP and the same dll i want to make use in that also. 现在,该应用程序需要新的转移,因为它应该升级到UWP和我想要使用的同样的dll。 What is the best and easiest methods available in UWP to import.Net Framework 2.0 dll ? UWP中可用的最佳和最简单的方法是import.Net Framework 2.0 dll?

Regards, Lal 问候,拉尔

You can create a .NET Standard 2.0 library project that can reference the legacy library and you can then reference this .NET Standard 2.0 project from you UWP app. 您可以创建可以引用旧库的.NET Standard 2.0库项目 ,然后可以从UWP应用程序引用此.NET Standard 2.0项目。

In the .NET Standard library, you can write custom types that access the legacy library and provide a "middleware layer" between the UWP app and the legacy library. 在.NET标准库中,您可以编写访问旧库的自定义类型,并在UWP应用程序和旧库之间提供“中间件层”。

What is the best and easiest methods available in UWP to import.Net Framework 2.0 dll ? UWP中可用的最佳和最简单的方法是import.Net Framework 2.0 dll?

You can not direct consume any full .NET Class Library from UWP app, there is some security restrictions. 您无法从UWP应用程序直接使用任何完整的.NET类库,但存在一些安全限制。 UWP project can reference libraries such as Universal Windows Class Library, .NET Standard library, Windows Runtime Component and so on. UWP项目可以引用通用Windows类库, .NET标准库, Windows运行时组件等库。

For solving this, since your app is for desktop devices and you already have a WPF app, I recommend you to convert the WPF app to UWP app by using Desktop Bridge . 为解决此问题,由于您的应用程序适用于桌面设备而且您已有WPF应用程序,因此我建议您使用Desktop Bridge将WPF应用程序转换为UWP应用程序。 Or you could try to convert the old dll into one of above the libraries that can be referenced by UWP app. 或者您可以尝试将旧的dll转换为UWP应用程序可以引用的库之上。 If you do only want to consume the .Net framework dll, you may try to create COM Proxy Stubs and work with them as communication layer, here is the official sample. 如果您只想使用.Net framework dll,您可以尝试创建COM代理存根并将它们作为通信层使用, 这里是官方示例。

One solution for this is to make a windows service and use that dll in service. 对此的一个解决方案是制作Windows服务并在服务中使用该DLL。 You can reference that service from UWP application in order to make all the API calls. 您可以从UWP应用程序引用该服务以进行所有API调用。

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

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