NMFCode / NMF

This repository contains the entire code for the .NET Modeling Framework
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Running Ecore2Code on .NET core #56

Closed wasowski closed 4 years ago

wasowski commented 4 years ago

Hi. I am trying to run NMF to generate .NET code from an Ecore meta-model and then do some constraint checking and transformations in .NET languages. I am planning to use these examples in our upcoming text book (http://mdsebook.org). Unfortunately, I am quite handicapped in .NET universe. Also I am insisting to use .NET Core (as far as I understand), or in no circumstances rely on Visual Studio, as all examples are cross-platform in the book, and I am developing these on Linux.

I installed dotnet-classic on Ubuntu (dotnet --version reports 3.1.201). I created an example project with dotnet new console and added NMF-Basics: dotnet add package NMF-Basics.

Ecore2Code is not added to the PATH, but I can find it in ~/.nuget/packages/nmf-basics/2.0.157/tools/Ecore2Code.exe. Unfortunately, I am unable to run it. dotnet ~/.nuget/packages/nmf-basics/2.0.157/tools/Ecore2Code.exe produces:

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/home/wasowski/.nuget/packages/nmf-basics/2.0.157/tools/'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the /home/wasowski/.nuget/packages/nmf-basics/2.0.157/tools/Ecore2Code.runtimeconfig.json file specifying the appropriate framework.

I am almost sure that my .NET handicap is the main issue here, so I apologize for asking basic questions, and hope for some guidance.

georghinkel commented 4 years ago

Hi,

at the moment as I have to admit, Ecore2Code is exclusively built against the .NET Framework, still with the assumption that the developer machines would run Windows. The libraries are all .NET Standard 2.0 so you can use them to develop applications that run on Linux systems, but the dev machine has to be Windows. I wanted to consolidate the tool to have it run as .NET Core global tool as well, but for some reason I never did.

Therefore, I will treat the issue as a feature request to export Ecore2Code as a .NET Core tool. I will have a look at it as soon as possible.

Best,

Georg

wasowski commented 4 years ago

Thanks @georghinkel . I know you are busy and this should not add stress. So in the meantime, I will try to find out a workaround. I can get access to a Windows machine and generate the code there, then just commit the code to my repo, which should, as you write, allow to run the rest for everybody else. Sorry to be so pushy, but could you tell me (as a non-Windows developer) what is my shortest route to running Ecore2Code on an ecore file in Windows? I would hugely appreciate a few lines to point me to the right trajectory. [I guess this might also help others who will land here via a Google search]

georghinkel commented 4 years ago

The reason Ecore2Code ships with the NuGet package is actually that it is immediately available in Visual Studio once you downloaded the package, because it adds the Tools Folder (where you found the tool) automatically to the PATH of the package Manager console inside VS. If you don't use Visual Studio, the easiest Thing would be to add the Directory to PATH manually (even though this is not very maintainable because the Directory contains the Version number). As an alternative, just start Ecore2Code with the full path.

georghinkel commented 4 years ago

Ecore2Code should be installable on Linux now using dotnet tool install --global NMF-Ecore2Code --version 2.0.160

wasowski commented 4 years ago

I am truly impressed how fast you were able to do it. I am trying to test it on Ubuntu right away!

wasowski commented 4 years ago

I am glad to confirm that it works. I got the code generated on Ubuntu 18.04 with .NET Core SDK 3.1.201. The install via snap messes up a few things. I had to manually set and export DOTNET_ROOT=/snap/dotnet-sdk/69/ but after this the tool started to work. The tool name is ecore2code on Linux.

All seems good. Now I will dabble in trying to compile this and integrate with my gradle builds. This is also going to be some fun.

PS. I did not manage to try the Windows route - you were faster releasing this, than me getting a Windows machine from my son :)

georghinkel commented 4 years ago

Thanks :)

.NET, specifically the .NET Core SDK, has a very neat commandline interface that should make it easy to integrate into gradle because you don't have to care about dependencies or anything, just make sure to call dotnet build <path-to-solution.sln> and you are good to go.