Accessing the SerialPort class using .Net Core 3.0
Asked Answered
F

3

16

I'm starting a new .NET Core 3.0 project in which I need to access the 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://learn.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. 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?

Feer answered 6/10, 2019 at 15:7 Comment(0)
F
24

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. I was able click QuickActions icon to install the package.

enter image description here

Feer answered 6/10, 2019 at 15:10 Comment(1)
Awesome , thanks for your good explantation @FeerHydroid
K
14

I am using .NET Core 3.1 building Blazor app. Visual Studio 2019 did not gave me context menu item "Install package 'System.IO.Ports'". I resolve this by going to DOS prompt.

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.

Kunlun answered 11/11, 2020 at 12:40 Comment(0)
R
10

I had the same issue and this worked for me. Just I downloaded and installed the package and all ok. Thanks.

You need to do the following: Tools > Command Line > Developer Command Prompt and execute the following commands: dotnet add package System.IO.Ports

You can also add it through NuGet packages.

Rockling answered 18/10, 2019 at 18:42 Comment(2)
You should add to your answer what package was it.Hardi
Go to Tools>Command Line>Developer Command Prompt and following commands: dotnet add package System.IO.PortsCaputo

© 2022 - 2024 — McMap. All rights reserved.