Generating Model code from Model.edmx in EF6 without Visual Studio

c# entity-framework-6 mono monodevelop t4


We don't utilize Visual Studio during the build process for our application, nor is it available on the build servers. The essential prerequisites for a reproducible build are all open source / freely available, however we have generally retained Visual Studio as a "nice to have" for creating the application.

I'm thinking about upgrading to EF6 right now. I need a method of generating Model code from the edmx file without using Visual Studio because I do not want to check in the created Model code.

Since EdmGen is included with the.NET framework, we have previously utilized it and are satisfied for our build servers to rely on it. Using T4 templates is the suggested method for producing code in EF6.

The T4 code creation tools, on the other hand, are part of Visual Studio and are not distributed separately.

The answer can be found in part at This inquiry. Both responses, however, have issues.

First, it is advised that the license enables you to copy the required files from your Visual Studio installation to the build server. This is an unsightly approach, too, as it prevents automated setup of new build servers and necessitates the presence of a Visual Studio installation. We also require the EF.Utility.CS.ttinclude from the Visual Studio installation for EF6 model generation. I have an email from a Microsoft developer claiming that, in his unofficial judgment, I would be permitted to copy that file as well, but after reading the licence, I am not so sure.

The second, and far more alluring, is an open-source TextTransform implementation in MonoDevelop. Again, though, we are missing the include file, and it's also unclear to me how exactly this TextTransform tool will handle the template that EF6 has provided. I've had problems thus far attempting to make it function.

So, does anyone have a functioning example of creating an EF6 model without utilizing tools that need installing Visual Studio?

5/23/2017 11:58:11 AM

Accepted Answer

I've got this working now. I ultimately settled on using MonoDevelop's the TextTransform open-source implementation as my option. It turns out that the template include files utilized by the Entity Framework-produced tt template are likewise freely accessible. They are offered from zz-9 to zz.

I had to make a few tweaks in order to get it to work with the Visual Studio template.

I have to get rid of the in PREPROCESSED_TEMPLATE Sign inGetNamespaceName .

Second, I needed to make a few minor adjustments to the include file. Zzz-31-zzz is the complete changed filename.

All the files you need are in that collection, but keep in mind that I can't ensure that the TextTransform binaries I've included there are the most recent versions; you should probably create your own or get them from a MonoDevelop installation instead. Simply include a file and run it by using:

./TextTransform.exe -out Models.cs -I INCLUDES

where "INCLUDES" refers to the folder containing the altered EF.Utility.CS.ttinclude.

5/23/2017 12:14:40 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow