6

For our application, we do not use Visual Studio in the build process; Visual Studio is not on the build servers. In general, we have kept Visual Studio as a "nice to have" for developing the application, but the crucial requirements for a reproducible build are all open source / freely available.

I am now considering upgrading to EF6. I do not want to check in the generated Model code, so I need a way of doing Model generation from the edmx file without requiring Visual Studio.

Previously, we have used EdmGen, as that is shipped with the .NET framework, and we are happy for our build servers to depend on that. In EF6, the recommended way to generate the code is using T4 templates.

However, the T4 code generation tools are built into Visual Studio and are not shipped separately.

This question contains part of the answer. However, there are problems with both answers.

Firstly, it is suggested that the licence allows you to copy the necessary files to the build server from your Visual Studio installation. However, this is an ugly solution, as it means setting a up a new build server can't be automated, and depends upon a Visual Studio installation being present. Additionally, for EF6 model generation, we also need the EF.Utility.CS.ttinclude in the Visual Studio installation. I have an email from one of the Microsoft devs saying that in his non-legal opinion, I would be allowed to copy that file too, but looking at the licence, I am not convinced.

Secondly, and much more attractively, there is an open-source implementation of TextTransform in MonoDevelop. However, again, we are missing that include file, and additionally, it's not clear to me that this TextTransform tool works exactly the same way, and can handle the template that EF6 has given me. So far I have errors trying to get it to work.

So: Does anyone have a working example of doing EF6 model generation without using tools that can only be got from a Visual Studio installation?

Community
  • 1
  • 1
Martin Eden
  • 6,143
  • 3
  • 30
  • 33
  • Solution: Use Code First. – Federico Berasategui Jan 03 '14 at 16:03
  • I'm not sure, but for ef 4/5 we have a fairly short list of steps to set up a build server. One of them involves copying those files, but it's not a big deal, and the zip has already been prepared. I could automate them if need be, (except for the vs test tools install, i think) but I don't see us spinning up build servers every 30 minutes. – Andrew Jan 03 '14 at 16:05
  • @HighCore: I can't use CodeFirst, because this project predates CodeFirst, and all of my investigations so far into migrating from the Edmx file to CodeFirst classes seem like a very large amount of work, for our model size. But, yes, I agree CodeFirst is a much more desirable way of doing things. – Martin Eden Jan 03 '14 at 16:17
  • 1
    @AndrewBacker: The thing is, we also distribute the source code to our client. The idea then is that if we were to go bust as a company, they already have and own all the files they need to build and run the application. If this zip file then becomes necessary, what do I do with it? I can't keep it in the source repository with everything else, because legally that counts as redistributing it to our client. I guess I could write a script that when run on a machine with Visual Studio generates you an archive for setting up a build server... but it's not a very nice solution. – Martin Eden Jan 03 '14 at 16:19
  • @Martin Edin: Ah, i see. So it's not really about build servers, but about bundling a tool so that they can generate the code without relying on VS. Build servers are a nice side effect. Very cool. But why are you alergic to including the vs tool output? I can understand philosophically... but I wouldn't think that would be a license issue. That sucks. I would like to know the solution myself. And then have us get rid of VsTest :) – Andrew Jan 03 '14 at 16:29
  • Maybe write Scott Hanselman? – Andrew Jan 03 '14 at 16:31
  • Part of the answer may be that you can get those template includes from https://entityframework.codeplex.com/SourceControl/latest#src/EFTools/EntityDesign/TextTemplates/Includes/ which has an open licence. So that's a step. – Martin Eden Jan 10 '14 at 12:37

1 Answers1

1

I now have this working. The solution I finished with was using the open-source implementation of TextTransform from MonoDevelop. It turns out that the template include files used by the tt template created by Entity Framework are also available under an open-licence. They are available from here.

In order to get it working with the template created by Visual Studio, I had to make the some changes.

In Model.tt, I had to remove the #if PREPROCESSED_TEMPLATE check in GetNamespaceName.

Secondly, I had to make some small modifications to the include file. The full modified file is here.

All the files you need to do this yourself are in that repository, although note that I don't guarantee that the binaries of TextTransform that I have included there are up to date - you should probably build your own / grab them out of a MonoDevelop install. Just add a Model.tt file, and invoke using:

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

where "INCLUDES" is the folder with the modified EF.Utility.CS.ttinclude in.

Community
  • 1
  • 1
Martin Eden
  • 6,143
  • 3
  • 30
  • 33
  • How did you get TT to run against the EdmGen output which goes to seperate files instead of Edmx? Or did you use a library to combine them? And did you find any difference between that metadata as generated by VS vs EdmGen? I've also been playing with getting this working and there's extremely little documentation for it, especially as an end to end solution including the class files etc. If you could write a little more about it that would be great. – Cody Konior Aug 31 '15 at 14:00
  • @CodyKonior: I no longer have access to the code, but as I recall, I am no longer using EdmGen at all. I just run TextTransform on the Model.tt file created by Visual Studio from the Edmx file. The output is just that single Model.cs file. – Martin Eden Sep 05 '15 at 07:47