Answered by:
visual studio t4 template(EF6) customization doesnt work

Question
-
The file names are MyModel.Context.tt and MyModel.tt
I have added new method (for Pascal casing the generated class names and property names) in the CodeStringGenerator Class (in the tt file) and implemented in the above tt files. and it works fine.
I took the solution to the next level by applying the changes to the centralized visual studio item templates folder (C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Data\1033\DbCtxCSEF6\(tt files)).
Then deleted the EDMX and related tf files and generated classes together.
I recreated the EDMX, but the custom changes didn't take effect I opened the .tt files and found that changes were not copied over and it just looked like the original unchanged version.
Any suggestion?- Edited by HasTeq Thursday, January 14, 2016 10:34 PM
Thursday, January 14, 2016 9:58 PM
Answers
-
I think your problem is that the templates are cached.
It'll be using those rather than the ones you changed.
For vs2015, on my computer the cached versions are:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplatesCache\CSharp\Data\1033\DbCtxCSEF6
I think you can force clearing the cache using
devenv /installvstemplates
From an admin vs command prompt
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Monday, January 25, 2016 6:04 AM
- Marked as answer by Fred Bao Tuesday, January 26, 2016 6:18 AM
Friday, January 15, 2016 8:12 PM
All replies
-
Hi HasTeq,
According to description, I’m not sure what kind of design patterns you using. Model first or database first? Did you upgraded your database after you added some new method in the CodeStringGenerator class. And do you create your edmx file from your database? Could you please provider some more information. And the following links about dealing the changes for your reference.
https://msdn.microsoft.com/en-us/data/jj205424
https://msdn.microsoft.com/en-us/data/jj206878
Best regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.Friday, January 15, 2016 10:02 AM -
It is a database first design. The problem is about centralizing the changes made to the template generators. I copied the changes to the Visual studio level item template folder and recreated the EDMX but didn't see the changes taking effect. Now according to another suggestion I created a folder in the project root with the name codeTemeplate and copied the template files there and working in that route I will post if it works out.Friday, January 15, 2016 12:46 PM
-
I think your problem is that the templates are cached.
It'll be using those rather than the ones you changed.
For vs2015, on my computer the cached versions are:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplatesCache\CSharp\Data\1033\DbCtxCSEF6
I think you can force clearing the cache using
devenv /installvstemplates
From an admin vs command prompt
- Proposed as answer by Zhanglong WuMicrosoft contingent staff Monday, January 25, 2016 6:04 AM
- Marked as answer by Fred Bao Tuesday, January 26, 2016 6:18 AM
Friday, January 15, 2016 8:12 PM -
Thanks Andy for trying to help.
I tried your suggestion : devenv /installvstemplates
It didn't help.
I tried copying the tt files to the common item plates location at (C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Data\1033\DbCtxCSEF6\(tt files))
I tried copying them into CodeTemplates folder in my project root
Restarted VS after devenv /installvstemplates command
So far no luck... I would appreciate any further help in trouble shooting
Monday, January 25, 2016 3:47 PM -
Thanks Andy for trying to help.
I tried your suggestion : devenv /installvstemplates
It didn't help.
I tried copying the tt files to the common item plates location at (C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Data\1033\DbCtxCSEF6\(tt files))
I tried copying them into CodeTemplates folder in my project root
Restarted VS after devenv /installvstemplates command
So far no luck... I would appreciate any further help in trouble shooting
Why can't you use partial class for this?
Monday, January 25, 2016 9:11 PM