Stuck in Xamarin...

Nov 15, 2014 at 5:03 AM
I'm using both BrightstarDB and Xamarin for the first time.

I'm comfy in VS.NET 2013 at work, but at home I use a Mac, and my goal is to use BrightstarDB in a web app I want to host on this box using mod-mono (which is already configured).

I've successfully added the BrightstarDB package to my solution using Xamarin's built-in NuGet manager. I'd like to set up EntityFramework, but I can't find a way to add the Brightstar Entity Context to my project. There is no "data" group in the "New File" dialog, and no other mention of this template that I can find.

Is there something I need to do manually to make this template available? Xamarin's NuGet manager mentioned that it could not run a PowerScript included in the package (but had no other install errors/warnings), could that be related to the template not showing up?
Coordinator
Nov 15, 2014 at 9:04 AM
Hi Richard,

The NuGet package BrightstarDB includes a .tt file named MyEntityContext.tt which should get dropped into the root folder of your project when you install the NuGet package. I've not tried with Xamarin studio, but I wonder if the problem is either that it is not recognizing the .tt file (though it should) or perhaps the project didn't get updated (so the file is there, but its not added to the project for some reason)? So first thing to do might be to check if you have that file in your file system directory and if so just manually add it in to the project.

If the file isn't there for some reason then probably the best thing to do would be to just download it from GitHub (https://github.com/BrightstarDB/BrightstarDB/blob/develop/src/tools/EntityFrameworkGenerator/MyEntityContext.tt). You can rename the file if you want to use a different name for the context and you can also move it to a different folder if you don't want it in the root namespace of your application.

If you can let me know how you get on (especially if any of the above fixes the issue for you) that would be really helpful as I can update the docs so that others don't get stuck in Xamarin too!

Cheers

Kal
Nov 15, 2014 at 3:42 PM
Hi Kal,

Thanks for the quick response!

I do have the MyEntityContext.tt file in my project... I guess I thought I needed to do something else before moving forward with creating entities.

I've created a few test interfaces, but when right-clicking on MyEntityContext.tt in Xamarin, there is no "Run custom tool" option, and no obvious synonyms. Building the solution doesn't generate any concrete classes for these interfaces either.
Coordinator
Nov 20, 2014 at 10:55 AM
Hi Richard,

I think it should be possible to set up the .tt file to be processed automatically by Xamarin Studio - take a look at this thread on the Xamarin support forum:

https://forums.xamarin.com/discussion/7573/run-t4-template-in-xamarin-studio

It may be that you need to manually set the "Custom Tool" property for the .tt file.

Cheers

Kal
Dec 31, 2014 at 8:14 AM
I am trying to test out BrightstarDB using Xamarin Studio on a mac;

I followed the thread and was added the custom tool setting

However, it fails to run the tt with the following error: MyEntityContext.tt(5,5): Error: Could not resolve include file 'EF.Utility.CS.ttinclude'.

it looks like EF.Utility.CS.ttinclude' is missing from xamarin studio on the mac
Coordinator
Jan 5, 2015 at 8:06 AM
Sorry for the late reply - just starting to catch up after the holidays.

I'll need to try this out on a Mac, but I suspect that the problem is as you say that the .ttinclude file isn't part of the Xamarin distribution. If you have access to a PC running VS, you should be able to find the file in the VS installation directory under Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes. On my PC (running VS2013) the full path to the file is C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes

In the long term I think I'll need to look at either rewriting the .tt file to remove the dependency or moving to a different form of code generation for our EF, but in the short term hopefully you can work around the problem.

If anyone else on a Mac has found a solution to this, please do let me know!

Cheers

Kal
Jan 24, 2015 at 7:48 AM
Edited Jan 24, 2015 at 7:49 AM
Note that Microsoft Web Developer Tools is a required installation component to get the EF.Utility.CS.ttinclude template. Copying that to the same directory as MyEntityContext.tt is a step forward, but there is still an error:
Error: The 'TextTemplatingFileGenerator' code generator crashed: No directive processor registered as 'T4VSHost'
I rather suspect the MyEntityContext.tt template will never work in Xamarin Studio until its dependencies on EnvDTE and the like are removed. I guess the difficulty here is that the template needs to "understand" the code in order to know what needs to be generated. Seems like it might be the perfect job for Roslyn (or NRefactory).

My only recourse right now is to run VS in a VM from my Mac and switch to the VM to regenerate my DB context as and when needed. Hardly ideal, but hopefully it will suffice until the template is rectified.
Coordinator
Jan 27, 2015 at 8:39 AM
kentcb wrote:
Note that Microsoft Web Developer Tools is a required installation component to get the EF.Utility.CS.ttinclude template.
That's worth keeping a note of to add to the docs if we manage to get this working on the Mac, thanks!
Copying that to the same directory as MyEntityContext.tt is a step forward, but there is still an error:
Error: The 'TextTemplatingFileGenerator' code generator crashed: No directive processor registered as 'T4VSHost'
I rather suspect the MyEntityContext.tt template will never work in Xamarin Studio until its dependencies on EnvDTE and the like are removed.
I'll have a look into this - the error seems to be more about Xamarin Studio's TT processor not understanding one of the directives in the included .tt file. See this page for more information. The author suggests actually removing the offending line from the .tt file.

Xamarin Studio does have some partial support for EnvDTE, so it might be worth another try with that t4vshost directive removed.
Coordinator
Jan 27, 2015 at 2:57 PM
I had a deeper dig and even after fixing up that issue with the T4VSHost reference, there are still problems with the EnvDTE references not working, so its not worth going any further down that road. I think for now you are probably stuck with having to generate the code in VS.