T4 code generator for Entity Framework - Failed to resolve include text for EF.Utility.CS.ttinclude
Asked Answered
S

2

7

I'm trying to automate build process for CI server of Silverlight 5 application using OpenRIA Services.

I've got database-first Entity Framework .edmx generated file from which DomainModel is generated, and as part of build I want to generate entities by T4 code generator.

Project settings

My server .csproj changes.

Imports

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
# Microsoft.TextTemplating.targets are added after CSharp.targets
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\TextTemplating\Microsoft.TextTemplating.targets"/>

and properties

<PropertyGroup>
    <TransformOnBuild>true</TransformOnBuild>
    ...
<PropertyGroup>

Installed sdk, and tools:

Broken build

Looks correct, but at build there is such a error

5>  Transforming template DomainModel\EntityConverters.tt...
5>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TextTemplating\Microsoft.TextTemplating.targets(396,5): error : Failed to resolve include text for file:C:\{path to my project}\DomainModel\EF.Utility.CS.ttinclude. Line=-1, Column=-1
5>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\TextTemplating\Microsoft.TextTemplating.targets(396,5): error : Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string. The transformation will not be run. . Line=21, Column=4

Suspicious

All .tt files has T4 import

<#@ include file="EF.Utility.CS.ttinclude"#> 

I have a suspicion that it's targeting local directory, not even build directory.

I'm curious why Microsoft.TextTemplating.targets variable is targeting EF.Utility.CS.ttinclude in {path to my project} not in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes where it really is. Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string seems legit according to this path.

Maybe I've missed some setting, import or path set? How I can change or update path for this utility?


Associated Q&A already checked:

Sanctimony answered 30/6, 2015 at 9:27 Comment(3)
Have you tried this https://mcmap.net/q/472039/-t4-templates-error-loading-the-include-file-ef-utility-cs-ttinclude-returned-a-null-or-empty-string or installing Microsoft Web Developer Tools and Microsoft SQL Server Data Tools?Soapwort
Instalation of Microsoft Web Developer Tools and Microsoft SQL Server Data Tools didn't helped. About this question - this is not the case. Event the workaround described in question didn't work in all cases.Sanctimony
Maybe it is possible to set full path in <#@ include file="..." #>Soapwort
S
2

Problem can be solved by adding absolute or relative path to EF.Utility.CS.ttinclude in your T4 file. For build server the best solution is probably to copy files that usualy can be found in path C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes to your project and then change the line:

<#@ include file="EF.Utility.CS.ttinclude"#>

to for example:

<#@ include file="..\..\EF.Utility.CS.ttinclude"#>

For some reason when template transformation is run from MSBuild it looks for .ttinclude files in the same location that .tt file is.

Soapwort answered 27/11, 2015 at 9:20 Comment(2)
But... WHY? Why the default VS installation has problems with files generated by itself?...Vowel
I am not sure that those files were generated by VS but from what I remember problem occurred only in MSBuild, in VS it worked.Soapwort
C
-1

I found i was able to keep the include file as

<#@ include file="EF.Utility.CS.ttinclude"#>

by adding the following to my config

  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
  <connectionStrings>
Cardin answered 18/9, 2017 at 16:31 Comment(1)
I'm no longer at the project and those problems, so its hard for me to verify - can you confirm does it generate entities when run manually from MS Build?Sanctimony

© 2022 - 2024 — McMap. All rights reserved.