This project is read-only.

T4MVC does not open files in source control?

May 8, 2013 at 7:36 PM
I am using the Perforce source control system and we use the P4VS plugin for Visual Studio to manage the files. However it seems when the T4MVC template is executed it only appears to open the T4MVC.cs file for editing. All the other generated files fail to be edited as they are not opened for write and are read-only on disk.

This maybe a limitation of the P4VS plugin, but it seems to work for everything else. Any ideas on how to make this work?
May 8, 2013 at 8:13 PM
Hmmm, I don't think that has come up before. T4MVC is using this, which claims:
Automatic checkout
When the template detects it is running in Visual Studio and that the file it needs to write to is currently in source control but not checked out it will check the file out for you.
I'm guessing it must work for TFS, or people would have complained. Maybe some difference with this particular plugin?
May 8, 2013 at 8:14 PM
You might want to debug CheckoutFileIfRequired, at the very end of T4MVC.

You can debug it by attaching another instance of VS to VS and opening the .tt file there.
May 8, 2013 at 8:21 PM
Yeah, it seems they are missing support for the SourceControl API for some reason. They said you can get access to it via this:

http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsqueryeditquerysave2%28v=vs.80%29.aspx

But so far I can't seem to find that interface in the Microsoft.VisualStudio.Shell.Interop namespace when building the T4 template.
May 8, 2013 at 8:25 PM
Looks like we are using a back leveled interop assembly, probably for compatibility with VS2008?

<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>

The interface I am trying to use is not there for that assembly, but when I remove the .8.0 to use the latest one (from VS2012), it does not compile that code.
May 8, 2013 at 8:40 PM
Ok, so it seems as though the IVsQueryEditSave2 interface must be a new way of doing things for later versions of Visual Studio. Using this interface I am able to get my T4 template to work. I had to change to use the latest version of Microsoft.VisualStudio.Shell.Interop and fix the code that broke (just some stuff moved around in namespaces). I changed my template so it will use the new method if it exists, or use the old method if not.

Do you want me to email you my file, or a diff of my changes? Might be useful to have this work in the production code if possible, as I am sure others might run into this also. Ideally I want Perforce to fix their plugin to support the old det.SourceControl interface, but until then this works (and I can fix my other T4 templates now!).
May 8, 2013 at 9:01 PM
Interestingly, the doc you pointed to makes it look like that interface has been around since VS 2005!

If you're comfortable sending a pull request, that's ideal. If not, you can just post your whole .tt file on a gist. We have to make sure it doesn't break other source control systems like TFS, though.
May 8, 2013 at 10:39 PM
Ok, all seems to be working for me now. I tried using a BeginInvoke like you are doing for the sc.SourceControl calls, but that does nothing it seems. Invoking it directly works though. I hope I did the fork and pull request correctly. Git is not my thing :)
May 9, 2013 at 1:15 AM
Looks good, it's in 3.6.4. Can you please verify that all works for you with that?
May 9, 2013 at 4:16 AM
Sure thing I will check it out tomorrow. I will have to check my tab settings. I always have tabs set to spaces not tabs but there must be a setting I missed for T4 :)

BTW what is the best syntax highlighter and intellisense system for T4? I used to use the devart one but it does not support VS2012, and the tangible one is really slow...
May 9, 2013 at 4:56 AM
I think it just uses the Plain Text settings so that's where you need to configure tabs.

A while back, I was using those T4 editors, but I gave up on them because of various issues, and I just use plain text. I haven't tried in a long time, so it's possible that some work ok.
May 9, 2013 at 10:13 PM
All works great, thanks!