locked
How to add new Code Generation Item for EF Designer? RRS feed

  • Question

  • Can anyone tell me how to create an Item Template that can be used by the EF designer for the Add Code Generation Item option? I have created the Item Template and it works like a dream! However, I can't figure out how to get it to show up in the Add Code Generation Item dialog. FWIW I'm using a VSIX Project to deploy the Item Template.
    Tuesday, February 7, 2012 3:46 PM

Answers

  • Hi Mike,

    Unfortunately, this doesn't look like a supported scenario. As best as I can tell, the project system appears to have hardcoded the template filenames when you invoke the "Add Code Generation Item..." command.

    The only way I could get the template to display, was to reuse one of the two .vstemplate filenames.

    As an experiment, I unzipped the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\AdoNetEntityDataModelT4CodeGenCSharp.zip file, tweaked the ADONETArtifactGenerator_T4CodeGenTemplateCS.vstemplate as follows:

    Then I rezipped and copied to C:\Users\eddo\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#, restarted, and there it was. I suspect you can deploy via VSIX as well, but given the hardcoded filename requirement here, you'll want to test your scenario very thoroughly.

    Sincerely,


    Ed Dore

    Thursday, March 1, 2012 7:31 PM

All replies

  • Hi Mike,

    I don't think Item template is for this propuse, the Item Template is for Add Item for normal projects.

    For "Add Code Generation Item", I suggest you take a look How to: Customize Object-Layer Code Generation (Entity Data Model Designer)

    If I misunderstand you, please let me know.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 8, 2012 1:17 AM
  • Hi Yi,

    I am aware of how to customize the object-layer code generation (as is specified by the link).  However, I created some new T4 files specifically for interacting with the EDMX file and would like the ability to add them to a project via the Add code Generation Item option.  

    If you could tell me how to add my custom T4 files to the Add Code Generation Item dialog I would really appreciate it.

    Thanks,
    Mike

    Wednesday, February 8, 2012 2:33 AM
  • Any ideas?
    Thursday, February 9, 2012 1:18 PM
  • Hi Mike,

    I don't know much about EF designer, I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Thank you for your understanding and support.
    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, February 10, 2012 6:25 AM
  • Thanks very much Yi!
    Friday, February 10, 2012 11:56 AM
  • Hi Mike,

    Unfortunately, this doesn't look like a supported scenario. As best as I can tell, the project system appears to have hardcoded the template filenames when you invoke the "Add Code Generation Item..." command.

    The only way I could get the template to display, was to reuse one of the two .vstemplate filenames.

    As an experiment, I unzipped the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\AdoNetEntityDataModelT4CodeGenCSharp.zip file, tweaked the ADONETArtifactGenerator_T4CodeGenTemplateCS.vstemplate as follows:

    Then I rezipped and copied to C:\Users\eddo\Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#, restarted, and there it was. I suspect you can deploy via VSIX as well, but given the hardcoded filename requirement here, you'll want to test your scenario very thoroughly.

    Sincerely,


    Ed Dore

    Thursday, March 1, 2012 7:31 PM
  • That's too bad.  It's not such a pain in the neck to do it manually but would have preferred to utilize the Add Code Gen Item command.  Thanks for looking into this Ed.
    Thursday, March 1, 2012 7:42 PM
  • Hi Mike,

    actually this is possible, and fairly easy, your template name just has to start with "ADONETArtifactGenerator". Sounds silly, yes, but it works.

    You can find a working sample in NQueries.


    Friday, October 26, 2012 7:26 PM
  • Awesome!  Thanks Michael.  I'll give it a try.
    Sunday, November 4, 2012 9:58 PM
  • Open up the Model diagram and select properties from inside the window, and make sure "Code Generation Strategy" is set to "default".  If it's set to "None" you won't see this option. 
    Monday, May 6, 2013 2:02 PM