T4MVC与TeamCity上的便携式区域

时间:2012-07-02 11:48:26

标签: msbuild teamcity t4mvc portable-areas

我的情况是我们有一个使用Portable AreasT4MVC的解决方案,它有一个单独的T4MVC项目,其中包含7个可移植区域和主MVC3应用程序的所有生成文件。我们遵循了here的说明,我们在构建解决方案时会自动生成类。

虽然在VS2010中这一切都在Debug&发布版本,但我遇到问题的地方是我试图让它在TeamCity上运行。

我已按照有关在构建服务器here上设置T4的说明进行操作,如果在构建服务器上运行msbuild,我可以看到它能够启动TextTemplate.exe并查看生成文件,问题是它永远不会找到要转换的文件。

在执行与在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>

执行此操作时,我使用/ v:diag set:

从msbuild获取以下输出
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)

似乎在构建服务器上,T4似乎无法找到需要引用的项目来生成必要的类。我已经尝试了输入文件夹和程序集引用的各种组合,但看不到让T4“看到”它需要的文件。

有人有任何想法如何解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

坦率地说,我不确定你是否可以使用它,因为T4MVC需要VS主机才能访问DTE对象模型。请参阅此相关主题:Using T4MVC with build script

答案 1 :(得分:0)

如果David Ebbo是对的,请从构建服务器上的命令行运行VS(devenv.exe)。

例如,您也无法使用msbuild构建.vdproj安装程序项目,因此我们从构建服务器上的命令行运行VS以构建安装程序...