modbus icon indicating copy to clipboard operation
modbus copied to clipboard

Migrate to modern .NET with SDK-style projects for cross-platform support

Open Copilot opened this issue 4 months ago • 0 comments

The solution targeted .NET Framework 4.5 using legacy project formats, preventing builds on systems without Windows-specific framework packs and limiting cross-platform deployment.

Changes

Project Structure

  • Core: Converted to SDK-style project with multi-targeting (.NET Standard 2.0 + .NET 8.0)
  • Terminal: Converted to SDK-style project targeting .NET 8.0
  • Removed obsolete packages.config and App.config files

Dependencies

  • Added System.IO.Ports 8.0.0 for cross-platform SerialPort support
  • Updated CommandLineParser 1.9.71 → 2.9.1

Code Updates

  • Updated Terminal to use CommandLineParser 2.x API (removed DefaultValue attribute, HelpOption method)
  • Fixed broken Terminal example code (incorrect API usage with ModbusRtuSession constructor and SendRequest overload)

Before/After

Before:

// Didn't compile - missing slaveAddress in constructor
var session = new ModbusRtuSession(new ModbusProtocolImpl(stream));
var response = session.SendRequest<ResponseFunc03>(1, 3, func03); // Wrong signature

After:

var session = new ModbusRtuSession(new ModbusProtocolImpl(stream), slaveAddress: 1);
var response = session.SendRequest<ResponseFunc03>(functionCode: 3, func03);

The library now builds on Windows, Linux, and macOS with modern .NET tooling.

Original prompt

This section details on the original issue you should resolve

<issue_title>Modern .NET support</issue_title> <issue_description>Hi! Your solution lacks modern .NET support, which limits cross-platform compatibility. Please consider adding support for recent .NET versions to improve usability across different platforms.

Thank you!</issue_description>

Comments on the Issue (you are @copilot in this section)

  • Fixes sontx/modbus#4

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot avatar Oct 27 '25 12:10 Copilot