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:

Community
  • 1
  • 1
michalczukm
  • 9,963
  • 6
  • 40
  • 47
  • Have you tried this http://stackoverflow.com/a/8210150/615522 or installing Microsoft Web Developer Tools and Microsoft SQL Server Data Tools? – rotman Aug 28 '15 at 10:41
  • 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. – michalczukm Aug 29 '15 at 13:19
  • Maybe it is possible to set full path in <#@ include file="..." #> – rotman Aug 30 '15 at 11:04

2 Answers2

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.

rotman
  • 1,641
  • 1
  • 12
  • 25
  • But... **WHY?** Why the default VS installation has problems with files generated by itself?... – Mad Scientist Apr 19 '18 at 08:57
  • 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. – rotman May 07 '18 at 12:19
-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>
workabyte
  • 3,496
  • 2
  • 27
  • 35
  • 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? – michalczukm Nov 19 '17 at 21:30