Recently I tried to run the TrakHound MTConnect components on Linux, without success. It seems, though, that TrakHound’s MTConnect.NET library can be made to work within a .NET Core 2.0 application relatively easily.
My first attempt was to add the NuGet package using dotnet add package MTConnect.NET
. This appeared to work, but I get warnings that the .NET Framework 4.6 version was loaded. When I try to run a test application, I then get a NullReferenceException when using the library.
After some experimentation, what ended up working was to clone the repository, then create a basic .csproj
file targeting .NET Core 2.0. From there, I could add a reference from my test project with dotnet add reference /path/to/MTConnect.NET.csproj
. The test project then built, ran, and pulled probe data from agent.mtconnect.org.
My modified .csproj file is as follows.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>library</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> </PropertyGroup> <ItemGroup> <PackageReferenceInclude="RestSharp"Version="106.2.1"/> </ItemGroup> </Project>
The various GenerateAssembly*Attribute tags are to circumvent a known issue with the build. This is my first foray into .NET Core, so I’m not sure what needs to be done to roll this into the existing .csproj project file, or to get the NuGet package to support .NET Core 2.0. Just a quick experiment to confirm that the library itself can work on a Linux box.
Would you be willing to walk me through this a little more in detail. I’m not getting the results. I have created a new project (I’m using visual studio 2017) and added a reference to the MTConnect.NET project. The new project is built using .NET Core 2.0, yet I cannot seem to use a lot of library calls and RestSharp is giving me an error.
Not sure if my previous comment was actually posted, so I apologize if this is a repeat. I tried this method and still have errors about the 4.6 framework. Maybe I’m just doing it wrong: I have a Consol Application (using VS 2017) built on .NET core 2.0, and using MTConnect. In this project I created a clone of the MTConnect.NET and created a reference to it. The clone and the project are in the same solution. Could that be an issue. I could really pick your brain a little on the details of how you got this working. Thanks.
Unfortunately I haven’t tried this in VS 2017. Tomorrow I’ll see if I can get a basic console application working in that version of VS.
Could you post the error messages that you’re getting?
“Package ‘MTConnect.NET 2.8.1.29291’ was restored using ‘.NETFramework, Version=v4.6.1’ instead of the target project framework ‘.NETCoreApp, Version=v2.1’. This package may not be fully compatible with your project.”
I’m able to access the library and use it but when running it, it halts up on creating a new MTConnectClient()
Sorry for the slow response. It sounds like project’s packages.config file is referencing the .NET 4.6 version of RestSharp.
I’ve been working on a fork of this library at https://github.com/pmcoltrane/MTConnect.NET. It’s not well-tested in VS2017, but you might use the src/NetStandard2.0/packages.config file for reference. I’m able to build a .NET Core 2.0 console application and perform a basic probe request with that project.