Building TrakHound’s MTConnect.NET library for .NET Core 2.0

Building TrakHound’s MTConnect.NET library for .NET Core 2.0

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: