你如何在VS2017中从.net项目中引用一个netstandard项目?

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

我有一个 netstandard2.0 项目,我用它来与 3rd 方网络服务交互.我需要在同一个解决方案中从较旧的 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:43:15,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1564362.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:项目   如何在   net   netstandard

    发布评论

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

    >www.elefans.com

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