locked
Generating EF POCOs using T4 at build time RRS feed

  • Question

  • I am trying to avoid checking in the POCO entities every time the model changes as that process is prone to error.  After modifying the project file to include the target and include directives I am still getting an error:

    Error 1 Running transformation: System.ArgumentNullException: Value cannot be null.
    Parameter name: Could not obtain DTE from host
       at Microsoft.VisualStudio.TextTemplatingA069E34884144C29D9B2475F61418647.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.VsEntityFrameworkTemplateFileManager..ctor(Object textTemplating)
       at Microsoft.VisualStudio.TextTemplatingA069E34884144C29D9B2475F61418647.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.Create(Object textTransformation)
       at Microsoft.VisualStudio.TextTemplatingA069E34884144C29D9B2475F61418647.GeneratedTextTransformation.TransformText()
       at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result). Line=0, Column=0 DataManagementInterfaces

    Oleg Sych mentions that: "For example, T4 templates in ASP.NET MVC and T4 Toolbox rely on the unique features of the MVC and Visual Studio hosts respectively" Pasted from <http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/> So I am assuming that this is another one of those cases where it simply can't be done?

     

    -Scott

    Wednesday, November 9, 2011 8:49 PM

All replies

  • Hi Scott,

    Did you build your project using a Build Server? Since T4 is a part of Visual Studio, you need to install Visual Studio to use T4 engine to build T4 related projects.

    If above is not the issue, I suggest you provide more information about your projects and the changes you made for your project.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, November 10, 2011 5:38 AM
  • Hello,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 15, 2011 5:29 AM
  • Sorry, I have been on a different project for a couple of days.  Anyway I created a class library, added an Edmx, switched the database generation to POCOs, moved the entities and the Context tt files to separate class library assemblies, and updated the reference inside the tt files to point back to the edmx project.

     

    Once you have done that if you unload and edit the class library with the entity tt in it, and add the following below the CSharp targets import.

      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    	<PropertyGroup>
    		<TransformOnBuild>true</TransformOnBuild>
    		<IncludeFolders>C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes</IncludeFolders>
    	</PropertyGroup>
    	<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />
    
    

    This xml snippet  is straight out of the article I referenced before, which was copied into MSDN as well.  Note that the path for your include may vary.  I was going to get it working first, and then worry about abstracting the path.

     

    Oh - and I am building in Visual Studio right now, not a build server.


    • Edited by ScottReed Tuesday, November 15, 2011 5:54 AM
    Tuesday, November 15, 2011 5:53 AM
  • HI ScottReed,

    Did you install the Microsoft Visual Studio 2010 Visualization & Modeling SDK? The TextTemplating tasks requires this SDK to work.

    The download site is http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23025

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 15, 2011 9:05 AM
  • Yes, I have it installed (actually it is the SP1 version, because I have the SP1 version of VS)

     

    Have you tried it yourself?  Do you have the problem?  If not this offers me hope.  I was assuming that the problem was a design decision (as per the article) - not - a bug on my machine.

    Tuesday, November 15, 2011 3:23 PM
  • Hello,

    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
    Wednesday, November 16, 2011 7:32 AM
  • it should work. Did you try to add the included folder to the below registry key

    HKLM\Software\Microsoft\VisualStudio\10.0\TextTemplating\IncludeFolders registry


    Tracy YU[MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, January 3, 2012 7:22 AM
  • I got the following error Get Visual Studio to run a T4 Template on every build (ERROR)

    Could you help me?

    Thursday, April 5, 2012 12:14 PM