如何将.NET dll参考添加到UWP项目? [英] How to add .NET dll reference to UWP project?

查看:58
本文介绍了如何将.NET dll参考添加到UWP项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个.NETv4.x的.NET dll项目.我将版本更改为4.6.1,并进行了重建,没有问题.当我尝试从UWP项目中向他们添加参照元素时,出现错误:

I have several .NET dll projects for .NETv4.x. I changed version to 4.6.1 and rebuilded without problems. When I try to add referene to them from my UWP project I get error:

该项目的目标是".NETCore",而文件参考的目标是'.NETFramework'.这不是受支持的方案.

The project targets '.NETCore' while the file reference targets '.NETFramework'. This is not a supported scenario.

我也无法从添加引用..."->项目"中引用.NET项目:

I can't also reference .NET projects from 'Add reference...'->'Projects':

无法添加对项目的引用

Unable to add a reference to project

但是在项目设置中,我看不到任何将其目标更改为".NETCore"的内容.是否可以从UWP项目中引用.NET4.x项目或将其转换为UWP项目类型?

But in project settings I can't see anything to change it's target to '.NETCore'. Is it possible to reference .NET4.x project from UWP project or convert it to UWP project type?

推荐答案

UWP项目可以引用通用Windows类库,可移植库或Windows运行时组件.您经典的.NET项目就是这些.

UWP project can reference Universal Windows Class Library, Portable Library or Windows Runtime Component. Your classic .NET projects are none of those.

如果您打算继续在经典.NET项目和UWP中开发和使用这些库,建议您尝试可移植库,在该库中可以选择目标平台,但是请注意,这种方法可能会有所限制,因为它对于可用的名称空间和类,采用最低的公分母.

If you're planning to continue to develop and use those libraries in both classic .NET projects and UWP, I suggest you try Portable Library in which you can choose target platforms, but beware that this approach can be somewhat limiting because it takes lowest common denominator for available namespaces and classes.

另一种方法是创建两个针对经典.NET和UWP的不同项目,并在它们之间共享代码,或者将文件添加为链接,或者使用Shared Project.然后解决条件编译的所有问题,进行构建,并在两种情况下都使用适当的输出.dll.

Another approach would be to create two different projects targeting classic .NET and UWP, and share the code between them either adding files as links or using Shared Project. Then resolve all problems with conditional compilation, build them and use appropriate output .dll's for both cases.

这篇关于如何将.NET dll参考添加到UWP项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆