简体   繁体   English

使用.Net Core 3.0 访问 SerialPort class

[英]Accessing the SerialPort class using .Net Core 3.0

I'm starting a new .NET Core 3.0 project in which I need to access the System.IO.Ports.SerialPort class.我正在开始一个新的 .NET Core 3.0 项目,我需要在其中访问 System.IO.Ports.SerialPort class。 The documentation I'm reading on the class shows that it is applicable to .NET Core 3 ( see the bottom of https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view=netcore-3.0 ). The documentation I'm reading on the class shows that it is applicable to .NET Core 3 ( see the bottom of https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?view =netcore-3.0 )。 However when I add a using statement to my class it isn't able to resolve System.IO.Ports.但是,当我向 class 添加 using 语句时,它无法解析 System.IO.Ports。 Is there some additional step that needs to be done to reference the SerialPort class for a .NET Core 3.0 program running on the Windows desktop?是否需要执行一些额外的步骤来引用在 Windows 桌面上运行的 .NET Core 3.0 程序的 SerialPort class?

Found the answer a few moments after I posted this question.在我发布这个问题后不久就找到了答案。 To use the SerialPort class there is an additional package that needs to be installed.要使用 SerialPort class,需要安装额外的 package。 I was able click QuickActions icon to install the package.我能够单击 QuickActions 图标来安装 package。

在此处输入图像描述

I am using .NET Core 3.1 building Blazor app.我正在使用.NET Core 3.1构建Blazor应用程序。 Visual Studio 2019 did not gave me context menu item "Install package 'System.IO.Ports'". Visual Studio 2019没有给我上下文菜单项“安装 package 'System.IO.Ports'”。 I resolve this by going to DOS prompt.我通过转到 DOS 提示符来解决这个问题。

cd <project_path>
dotnet add package Microsoft.Extensions.Configuration --version 5.0.0
dotnet add package System.IO.Ports --version 5.0.0

That seem to solve the problem.这似乎可以解决问题。

I had the same issue and this worked for me.我有同样的问题,这对我有用。 Just I downloaded and installed the package and all ok.只是我下载并安装了 package,一切正常。 Thanks.谢谢。

You need to do the following: Tools > Command Line > Developer Command Prompt and execute the following commands: dotnet add package System.IO.Ports您需要执行以下操作:工具 > 命令行 > 开发人员命令提示并执行以下命令: dotnet add package System.IO.Ports

You can also add it through NuGet packages.您也可以通过 NuGet 包添加它。

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

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