سؤال

I have a situation where we have a solution that uses Portable Areas and T4MVC which has a separate project for T4MVC where all the generated files for the 7 portable areas and main MVC3 application. We have followed the instructions here we are automatically generating the classes when building the solution.

Whilst in VS2010 this all works fine in both Debug & Release builds but where I am running into issues is where I am trying to get this to run on TeamCity.

I have followed the instructions on setting up T4 on a build server here and if run msbuild on the build server I can see that it is able to fire up TextTemplate.exe and look to generate files, the problem is that it never finds the files to transform.

I have managed to reproduce the same behavior on my local machine when executing the same build script as is run on TeamCity.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">

  <PropertyGroup>
    <Configuration>Release</Configuration>
    <TransformOnBuild>true</TransformOnBuild>
    <TransformFile>T4MVC\T4MVC.tt</TransformFile>
    <OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
  </PropertyGroup>


  <ItemGroup>
    <None Include="T4MVC\T4MVC.tt">
      <OutputFilePath>$(MSBuildProjectDirectory)\T4MVC</OutputFilePath>
    </None>
  </ItemGroup>

  <ItemGroup>
    <ProjectsToBuild Include="**\*proj" Exclude="ThemeGenerator\**" />
  </ItemGroup>

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" />

  <Target Name="Clean">
    <ItemGroup>
      <BinFiles Include="*\bin\*.*" />
    </ItemGroup>
    <Delete Files="@(BinFiles)" />
  </Target>

  <Target Name="Build" DependsOnTargets="Clean;Transform">
    <MSBuild Projects="@(ProjectsToBuild)"
             ContinueOnError="false"
             Properties="Configuration=$(Configuration)" /> 
  </Target>
</Project>

When this executes I get the following output from msbuild with /v:diag set:

Building with tools version "4.0".
Target "CreateCandidateT4ItemList: (TargetId:2)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" from project "C:\TeamCity\buildAgent\work\daad348639a87062\Project_Build.xml" (target "Transform" depends on it):
Using "Message" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "Message" (TaskId:2)
  Creating a list of candidate items that might need to be processed by T4 items (TaskId:2)
Done executing task "Message". (TaskId:2)
Using "CreateItem" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "CreateItem" (TaskId:3)
Done executing task "CreateItem". (TaskId:3)
Done building target "CreateCandidateT4ItemList" in project "Project_Build.xml".: (TargetId:2)
Target "SelectItemsForTransform: (TargetId:3)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemp
lating.targets" from project "C:\TeamCity\buildAgent\work\daad348639a87062\Project_Build.xml" (target "Transform" depends on it):
Task "Error" skipped, due to false condition; ($(TransformFile)=='') was evaluated as (C:\TeamCity\buildAgent\work\daad348639a87062\T4MVC\T4MVC.tt=='').
Initializing task factory "CodeTaskFactory" from assembly "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Build.Tasks.v4.0.dll".
Using "FilterCandidatesBasedOnItemSpec" task from the task factory "Code Task Factory".
Task "FilterCandidatesBasedOnItemSpec" (TaskId:4)
Done executing task "FilterCandidatesBasedOnItemSpec". (TaskId:4)
Done building target "SelectItemsForTransform" in project "Project_Build.xml".: (TargetId:3)
Target "CreateT4ItemLists: (TargetId:4)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" from project "C:\TeamCity\buildAgent\work\daad348639a87062\Project_Build.xml" (target "ExecuteTransformations" depends on it):
Task "Message" (TaskId:5)
  Creating T4 items lists for project  ()... (TaskId:5)
Done executing task "Message". (TaskId:5)
Done building target "CreateT4ItemLists" in project "Project_Build.xml".: (TargetId:4)
Target "ExecuteTransformations: (TargetId:5)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.targets" from project "C:\TeamCity\buildAgent\work\daad348639a87062\Project_Build.xml" (target "Transform" depends on it):
Using "TransformTemplates" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.Build.Tasks.dll".
Task "TransformTemplates" (TaskId:6)
  Directive processors: (TaskId:6)
    {none} (TaskId:6)
   (TaskId:6)
  Include folders: (TaskId:6)
    {none} (TaskId:6)
   (TaskId:6)
  Assembly references: (TaskId:6)
    {none} (TaskId:6)
   (TaskId:6)
  Reference paths: (TaskId:6)
    {none} (TaskId:6)
   (TaskId:6)
  Parameter values: (TaskId:6)
    {none} (TaskId:6)
   (TaskId:6)
  Full list of templates passed in : (TaskId:6)
    {none} (TaskId:6)
   (TaskId:6)
  Performing full T4 transformation (TaskId:6)
    MinimalRebuildFromTracking = True (TaskId:6)
    forcedRebuildRequired = False (TaskId:6)
  \tTrackerLogDirectory = <null> (TaskId:6)
  Tracking is disabled. TrackerLogDirectory has not been specified (TaskId:6)
Done executing task "TransformTemplates". (TaskId:6)
Using "PreprocessTemplates" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TextTemplating\v10.0\Microsoft.TextTemplating.Build.Tasks.dll".
Task "PreprocessTemplates" (TaskId:7)
  Directive processors: (TaskId:7)
    {none} (TaskId:7)
   (TaskId:7)
  Include folders: (TaskId:7)
    {none} (TaskId:7)
   (TaskId:7)
  Assembly references: (TaskId:7)
    {none} (TaskId:7)
   (TaskId:7)
  Reference paths: (TaskId:7)
    {none} (TaskId:7)
   (TaskId:7)
  Parameter values: (TaskId:7)
    {none} (TaskId:7)
   (TaskId:7)
  Full list of templates passed in : (TaskId:7)
    {none} (TaskId:7)
   (TaskId:7)
  Performing full T4 preprocessing (TaskId:7)
    MinimalRebuildFromTracking = True (TaskId:7)
    forcedRebuildRequired = False (TaskId:7)
  \tTrackerLogDirectory = <null> (TaskId:7)
  Tracking is disabled. TrackerLogDirectory has not been specified (TaskId:7)
Done executing task "PreprocessTemplates". (TaskId:7)

It would appear that on the build server T4 seems unable to find the projects that it needs to reference to generate the necessary classes. I have tried various combinations of input folders and assembly references but see unable to get T4 to "see" the files it needs.

Does anybody have any ideas how to resolve this?

هل كانت مفيدة؟

المحلول

Frankly, I'm not sure that you can get that to work at all because T4MVC needs the VS host in order to access the DTE object model. See this related thread: Using T4MVC with build script

نصائح أخرى

If David Ebbo is right, run VS (devenv.exe) from command line on your build server.

For example you can't build .vdproj installer projects using msbuild too, so we are running VS from command line on the build server to build the installers...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top