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

Using NMF metamodels in Unity #59

Closed RobertWalterU3d closed 4 years ago

RobertWalterU3d commented 4 years ago

Hi, I 'm new to this project so I might be doing something fundamentally wrong.

I followed this video tutorial: https://www.youtube.com/watch?v=NIMYuwTltVs&feature=youtu.be (First steps with NMF)

I was able to generate my C# types from my ecore file as well as the *.nmf file. My issue stems from the fact that I try to now use these generated files in the context of a Unity package, which usually doesn't have an AssemblyInfo.cs file to register the ModelMetadata. I'm a bit lost (since I'm also new to Unity) to understand how I can register the ModelMetadata in a Unity package. Any help would be appreciated.

georghinkel commented 4 years ago

Hi,

the AssemblyInfo.cs is only recommended because it fits into the common conventions as a place that stores assembly-wide attributes/annotations. However, since Microsoft decided to migrate the information that used to be contained in the AssemblyInfo.cs to the project file for SDK-based project files, many projects do not have an AssemblyInfo.cs anymore.

The short solution is, simply put the code somewhere else. I would recommend to create a file called ModelRegistrations.cs or similar such that peer developers have a place where they can look whether there are models registered. However, the exact location totally doesn't matter, the distribution of code to C# files entirely disappears during build (and is afterwards only contained in PDBs that you don't distribute).

Best,

Georg

RobertWalterU3d commented 4 years ago

Thanks, can you point me to the code that allows me to register the model?

georghinkel commented 4 years ago

It is really just the annotation that you have to add like here:

https://github.com/NMFCode/NMF/blob/b0362ec5683867748d3e961ebc70e0c5cdb4012e/Models/Models.Tests/Properties/AssemblyInfo.cs#L39

The first argument is the URI for which you want to register the model, usually the namespace URI, and the second one is the name of the embedded resource. It does not have to include the default namespace, NMF will also look for embedded resources that end with whatever you provided.

RobertWalterU3d commented 4 years ago

okay, now I get this exception when trying to call the ctor ModelRepository: Exception: The assembly Unity.StoryGraph, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null declares a model but has no embedded resources. Did you forget to embed a model?

I guess it is caused by my sgl.nmf is not recognized as an embedded resource, not sure how to achieve that...