你如何在VS2017中从.net项目中引用一个netstandard项目? [英] How do you reference a netstandard project from .net project in VS2017?

查看:26
本文介绍了你如何在VS2017中从.net项目中引用一个netstandard项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 netstandard2.0 项目,我用它来与 3rd 方网络服务交互.我需要在同一个解决方案中从较旧的 .net 4.6.2 项目中引用该项目,但是当我这样做时,我会收到一堆关于需要引用我定义的类型的错误.

I have a netstandard2.0 project that I'm using to interface with a 3rd party web service. I need to reference that project from an older .net 4.6.2 project in the same solution, but when I do I get a bunch of errors about needing references to types that I have defined.

例如,我将调用 netstandard 库中返回 Task 的方法,但我会收到一条错误消息,提示我需要对 System.Threading.Tasks 的引用,即使我已经有了.

For example, I'll call a method in the netstandard library that returns Task, but I'll get an error saying I need a reference to System.Threading.Tasks even though I already have one.

推荐答案

我认为这里有两个问题.

I believe there are two issues here.

只有某些版本的 .netstandard 可以与某些版本的 .net 4.X.Y 配合使用

要解决此问题,您可能需要更改一个或两个项目的版本.使用图表确定哪些版本可以一起兼容:https://docs.microsoft.com/en-us/dotnet/standard/net-standard

To resolve this you may need to change the version of one or both projects. Use the chart to figure out which versions are compatible together: https://docs.microsoft.com/en-us/dotnet/standard/net-standard

  1. 选择您的项目
  2. 右键单击属性
  3. 在应用程序"选项卡上,使用目标框架"下拉菜单根据需要更改框架

.net 4.X.Y 使用 4.0.0.0 系统库,而 .netstandardX.Y 使用 4.3.0.0

要解决此问题,您需要添加并引用 netstandard.library NuGet 包.

To resolve this you need to add and reference the netstandard.library NuGet package.

  1. 选择您的项目
  2. 右键单击管理 NuGet 包..."
  3. 在浏览"选项卡上搜索netstandard.library"
  4. 选择您需要的版本并安装(我相信它基于您最终使用的 .netstandard 版本)
  5. 导航到每个引用错误,右键单击它,然后添加缺少的引用

这篇关于你如何在VS2017中从.net项目中引用一个netstandard项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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