如何在VS2017中引用.net项目中的netstandard项目?

编程入门 行业动态 更新时间:2024-10-27 16:31:37
本文介绍了如何在VS2017中引用项目中的netstandard项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个netstandard2.0项目,用于与第三方Web服务进行交互.在相同的解决方案中,我需要从一个较旧的 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 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.

只有standard的某些版本才能与 4.X.Y的某些版本一起使用

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

  • 选择您的项目
  • 右键单击属性
  • 在应用程序"标签上,使用目标框架"下拉菜单根据需要更改框架
  • 4.X.Y使用4.0.0.0系统库,而standardX.Y使用4.3.0.0

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

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

  • 选择您的项目
  • 右键单击管理NuGet软件包..."
  • 在浏览"标签上搜索"netstandard.library"
  • 选择所需的版本并安装(我相信它基于您最终使用的standard版本)
  • 导航到每个参考错误,右键单击它,然后添加缺少的参考
  • 更多推荐

    如何在VS2017中引用.net项目中的netstandard项目?

    本文发布于:2023-11-06 17:41:32,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1564356.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:项目   如何在   net   netstandard

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!