New Posts New Posts RSS Feed: T4 templates getting overwritten if you click the DevForce Template dropdown
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

T4 templates getting overwritten if you click the DevForce Template dropdown

 Post Reply Post Reply
Author
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Topic: T4 templates getting overwritten if you click the DevForce Template dropdown
    Posted: 12-Aug-2011 at 1:38pm
6.1.2.0 - There is a drop down on the EDMX properties called DevForce Template that now has Standard or CodeFirst as choices.  If you open a model and just click the drop down, not even changing it, our custom T4 template gets overwritten with the standard Devforce t4 domain model template.   This leads to hours of debugging fun. </sarcasm>
 
I could see writing a new T4 if I didn't have one or if I actually switched the model to CodeFirst but why would just clicking on it overwrite the existing T4?  And if I did accidentally switch to CodeFirst or even just clicked again on Standard, shouldn't you warn the user that you're going to wipe out their files?
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 13-Aug-2011 at 3:44pm
More info: it seems that the T4 also gets replaced and the custom tool namespace cleared if you update an existing model from the db.  This time, I didn't touch any dropdowns; just added 2 new entities to the model, set up an association and saved.
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 13-Aug-2011 at 3:57pm
Once last note: even if you reset these from Visual Studio back to your own T4, the project file still has a reference to the DomainModel template that you need to remove manually.
 
      <TemplateName>DomainModelTemplate</TemplateName>
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 15-Aug-2011 at 4:27pm
Hi pk55;

I couldn't repro both of your issues. I clicked the drop down menu as well as update the model by adding new entities. In both cases, my custom tt file and custom tool namespace stay the same.

I've uploaded my repro solution here. Maybe you can tell me what I did differently than your solution.

Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 15-Aug-2011 at 10:43pm
Yes I see that your solution doesn't have that problem.  I tried all sorts of stuff to break yours to make it look more like ours (lots of data models, linked SL/server projects, nested folders for the models and T4s.....) and nothing worked and then I realized there's one more thing your solution didn't have; it wasn't under TFS source control.
 
The thing I've noticed is that for whatever reason, TFS isn't checking out the *.ReadMe file that gets generated by the T4 template (along with the more important *.IB.Designer file).  Which means the process that runs the T4 on save (the setting in the model is called "Transform Related Text Template") seems to think there isn't a T4 and so it creates a new one and uses the DevForce default of DomainTemplate. It's the equivalent to there not being a *.tt file associated with the model and that process generates a new one on save.  Not sure who 'owns' that process; EF or DevForce.
 
So the odd thing is, this worked in 6.1.2."e".  Our TFS hasn't changed; it's always had an issue with the read me files and seems to not be able to check them out for edit.  Is it possible something changed in the final 6.1.2.0 release that would start doing this (creating a new T4 if it thinks there isn't one)?
 
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 16-Aug-2011 at 9:16pm
Finally figured this out after poking around with Reflector in your IdeaBlade.VisualStudio.OM.Designer.dll.
 
Your extension gets called by VS when the model is saved and in the OnBeforeModelSaved method, you call AddDevForceTemplate.  That code 'assumes' that if the project file doesn't have an attribute named "TemplateName" with one of two specific string values, that there isn't a valid T4 template and you need to delete any existing ones and create the new T4 file from your stock DomainModelTemplate. 
 
Obviously all new projects created with 6.1.2.0 will have the attribute (which is why yours won't break) but projects created in previous versions won't.  You need to tell people in the breaking changes that if they have custom tool namespaces or custom T4 code generation, that they have to manually edit the project file and add that attribute to each model (for those that have multiple models).
 
Prove it by editing your project file and removing this line from your T4 section of your model and then update your model and save.  You'll see the template getting wiped out as well as the custom tool namespace:
      <TemplateName>DomainModelTemplate</TemplateName>
For Code First, it must be named:
      <TemplateName>DomainModelTemplateCodeFirst</TemplateName>
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 17-Aug-2011 at 11:56am
pk55;

Thanks for figuring this out. This one was very subtle and I apologize that it was not mentioned in the release notes. As with every breaking change, we always try to make them backwards compatible and I think this one should be. But let me discuss this first with a senior engineer and let you know what we decide.
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 17-Aug-2011 at 12:05pm
Easy to see how this could be missed since it works for new projects.
 
It seems that the best fix would be to not just depend on the attribute being there in the project file but to only create the file if the project item doesn't already exist.  But definitely at least mention it in the next release notes. 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 17-Aug-2011 at 12:29pm
Ok, I've filed a bug report for this. Will update you when this is fixed.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 22-Aug-2011 at 12:48pm
pk55;

This is fixed. Let me know if you want a patch for this.
Back to Top
pk55 View Drop Down
Senior Member
Senior Member


Joined: 22-Jul-2009
Location: CA
Posts: 105
Post Options Post Options   Quote pk55 Quote  Post ReplyReply Direct Link To This Post Posted: 22-Aug-2011 at 1:10pm
We don't really need a patch for this (we've already added the attribute to the project files) unless the patch also has the fix for the bug related to the ReferenceStrategy.NoLoad not working correctly:
 
 
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 22-Aug-2011 at 5:34pm
Actually, the patch for that bug has already been built. I've already asked the engineer who's working on that issue and I believe he will send that patch to stephenmcd soon. You can reply to that post to ping him again.

Otherwise, I'll consider this item resolved. Thanks again for tracking this down.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down